MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc.
MongoDB works on the concept of collections and documents. A database is a physical container for collections. Each database gets its own set of files on the file system. A collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Documents within a collection can have different fields. A Document is a set of key-value pairs. Documents have a dynamic schema which means that documents in the same collection do not need to have the same set of fields.
In order to use MongoDB with Node.js:
Step 1: Installation
You need to first install MongoDB and Node in your system.
Step 2: Set up MongoDB
After successful installation, You would need to start MongoDB and create a database.
Step 3: Start using MongoDB with Node.js
Now, for using MongoDB with Node.js, You need to install MongoDB module with the help of npm (Node Package Manager) in Node.js.
You can install MongoDB module by using the following command:
`npm install mongodb`
Then, you can include MongoDB in any application:
`const MongoClient = require(‘mongodb’).MongoClient;`
Then connect to the database:
```
MongoClient.connect(‘mongodb://localhost:27017/mydb’, function(err, db) {
if (err) {
return console.dir(err);
}
console.log(“We are connected”);
});
```
Lastly, you can perform database operations like insert, update, delete, find etc.
This is a very basic guide to start with MongoDB & Node.js. There are several other functionalities and operations we can use with MongoDB & Node.js in the real-time applications development.