Install mongodb shell

choco install mongodb-shell

Install mongodb shell with Chocolatey – Windows 11

mongosh
Current Mongosh Log ID: 655443dea5099d66fb01846f
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.2
Using MongoDB:          4.2.8
Using Mongosh:          2.0.2

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting
   2023-11-14T18:51:29.066-0500:
   2023-11-14T18:51:29.072-0500: ** WARNING: Access control is not enabled for the database.
   2023-11-14T18:51:29.074-0500: **          Read and write access to data and configuration is unrestricted.
   2023-11-14T18:51:29.081-0500:
   2023-11-14T18:51:29.084-0500: ** WARNING: This server is bound to localhost.
   2023-11-14T18:51:29.086-0500: **          Remote systems will be unable to connect to this server.
   2023-11-14T18:51:29.089-0500: **          Start the server with --bind_ip <address> to specify which IP
   2023-11-14T18:51:29.091-0500: **          addresses it should serve responses from, or with --bind_ip_all to
   2023-11-14T18:51:29.092-0500: **          bind to all interfaces. If this behavior is desired, start the
   2023-11-14T18:51:29.093-0500: **          server with --bind_ip 127.0.0.1 to disable this warning.
   2023-11-14T18:51:29.094-0500:
------

Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
  You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.
Start mongodb shell
test> show databases
admin    40.00 KiB
blog      8.00 KiB
config  108.00 KiB
local    40.00 KiB
show databases
test> use blog
switched to db blog
blog> db.articles.insertMany ([
... {
...         name: 'learn-react',
...         upvotes: 0,
...         comments: [],
...     },
...     {
...         name: 'learn-node',
...         upvotes: 0,
...         comments: [],
...     },
...     {
...         name: 'mongodb',
...         upvotes: 0,
...         comments: [],
...     }
... ])
{
  acknowledged: true,
  insertedIds: {
    '0': ObjectId("6554446fa5099d66fb018470"),
    '1': ObjectId("6554446fa5099d66fb018471"),
    '2': ObjectId("6554446fa5099d66fb018472")
  }
}
blog>
Insert test data into Collection: blog Document: articles

// Add mongodb to project
npm install mongodb

// Add MongoClient
import { MongoClient } from 'mongodb';

// Add End Point
app.get('/api/articles/:name', async (req, res) => {
    //const name = req.params.name;
    console.log(req.params);
    const { name } = req.params;
    const client = new MongoClient('mongodb://127.0.0.1:27017');
    await client.connect();

    const db = client.db('blog');

    const article = await db.collection('articles').findOne({ name });
    res.json(article);
});
Add mongodb to project and configure end-point

Test End-Point with Postsman