Category: 03. MongoDB

  • Node.js MongoDB Remove

    In MongoDB, you can delete records or documents by using the remove() method. The first parameter of the remove() method is a query object which specifies the document to delete. Example Remove the record of employee whose address is Ghaziabad. Create a js file named “remove.js”, having the following code:PauseNextMute Current Time 0:09 / Duration 18:10 Loaded: 4.77%  Fullscreen…

  • Node.js MongoDB Sorting

    In MongoDB, the sort() method is used for sorting the results in ascending or descending order. The sort() method uses a parameter to define the object sorting order. Sort in Ascending Order Example Sort the records in ascending order by the name. Create a js file named “sortasc.js”, having the following code:PlayNextMute Current Time 0:00 /…

  • Node.js MongoDB Filter Query

    The find() method is also used to filter the result on a specific parameter. You can filter the result by using a query object. Example Filter the records to retrieve the specific employee whose address is “Delhi”. Create a js file named “query1.js”, having the following code:PlayNextMute  FullscreenBackward Skip 10sPlay VideoForward Skip 10s Open the command…

  • Node.js MongoDB Select Record

    The findOne() method is used to select a single data from a collection in MongoDB. This method returns the first record of the collection. Example (Select Single Record) Select the first record from the ?employees? collection.PlayNextMute Current Time 0:03 / Duration 18:10 Loaded: 3.67%  Fullscreen Create a js file named “select.js”, having the following code: Open the command…

  • Node.js MongoDB Insert Record

    The insertOne method is used to insert record in MongoDB’s collection. The first argument of the insertOne method is an object which contains the name and value of each field in the record you want to insert. Example (Insert Single record) Insert a record in “employees” collection.PlayNextMute Current Time 0:05 / Duration 18:10 Loaded: 4.04%  Fullscreen Create a…

  • Node.js MongoDB Create Collection

    MongoDB is a NoSQL database so data is stored in collection instead of table. createCollection method is used to create a collection in MongoDB. Example Create a collection named “employees”. Create a js file named “employees.js”, having the following data:PauseNextMute Current Time 0:09 / Duration 18:10 Loaded: 4.77%  Fullscreen Open the command terminal and run the following command:…

  • Node.js MongoDB Create Database

    To create a database in MongoDB, First create a MongoClient object and specify a connection URL with the correct ip address and the name of the database which you want to create. Note: MongoDB will automatically create the database if it does not exist, and make a connection to it. Example Create a folder named…

  • Node.js Create Connection with MongoDB

    MongoDb is a NoSQL database. It can be used with Node.js as a database to insert and retrieve data. Download MongoDB Open the Linux Command Terminal and execute the following command: It will download the latest MongoDB according to your system requirement. Install MongoDB After the complete download, use the following command to install MogoDB.PlayNextMute…