-3

please briefly explain what are the differences between mongoose, mongodbapi & mongos

Does it come with the installation of MongoDB or do they need extra installations?

whoami - fakeFaceTrueSoul
  • 17,086
  • 6
  • 32
  • 46

1 Answers1

1

You need to know these keywords when you're talking about MongoDB database, Explaining all these as most of them are inter -linked.

Database keywords :

  • MongoDB : By now you might have known what mongo database is, which is basically schema-less. So which uses JSON structure to store data into it, Each record is called a document & table is called a collection. So each document in a collection can have different key-value pairs cause MongoDB is schema-less. Ref : Introduction-to-MongoDB & check this for hosting free MongoDB in cloud MongoDB-atlas.
  • Replica set : So let's talk about internal mechanism - In general MongoDB will be hosted as a replica set for high availability & redundancy. A replica set should have odd no.of shards(nodes/servers/mongod's) with one primary & remaining are secondary, ideally 3 shards (1P & 2S) you'll end-up connecting to cluster. Where by default primary will take reads & writes then eventually data will be sync'd to secondaries - You can configure different types for secondaries where few don't take any data, they are there for different reasons (Mainly to store data for redundancy & also to act as voters if an election occurs) Ref : replication
  • mongod : A mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data access, and performs background management operations. So each shard in a replica set is nothing but a mongod process. Ex:- When you install MongoDB in local you'll start mongod & then execute mongo to access database. Ref : mongod
  • Sharding : Sharding is a method for distributing data across multiple machines. So sharding has a group of replica sets where each replica set has different data of same application. you'll go to sharding only if you've large datasets & larger than the system’s RAM stress the I/O capacity of disk drives. In general if you're starting from scratch you might not need it that early. Ref : sharding

  • mongos : So when you finally have to do sharding & have a sharded cluster then mongos instances provide the interface between the client applications and the sharded cluster. mongos will route queries to respective shard(replica set). So you'll connect to mongos rather than a replica set. Ref : mongos

Driver keywords :

  • MongoDB Driver : When you're using node.js for development & say mongodb driver then it is native mongodb driver which is pretty much sufficient to access database through code. Ref : node-mongodb-native

    const MongoClient = require('mongodb').MongoClient;
    
  • Mongoose : This is a node.js library/driver which is a wrapper to mongodb driver. It is an Object Data Modeling (ODM). In basic terms to say, as MongoDB is schema-less if you wanted to make it work like SQL which is schema based then you can use mongoose. So you can create schemas for collections - which can be used for schema validation while writing data to DB that way you can ensure your collection has certain data across all documents, Though using this driver is optional but there are mixed-opinions from users & many features which might lean you towards it. Ref : mongoosejs & Introduction-to-mongoose

    const mongoose = require('mongoose')
    

    There are many other drivers based on language. Ex:- PyMongo for python.

Shell keywords :

  • Mongo Shell : The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mongo shell to query and update data as well as perform administrative operations. But in general you'll use mongo-compass or robo3T to access MongoDB. Ref : mongo-Shell
whoami - fakeFaceTrueSoul
  • 17,086
  • 6
  • 32
  • 46