简体   繁体   中英

What is MongoDB instances? Why could you possible not perform CRUD operations or access Mongo Command line shell?

A MongoDB instance can be thought of a single running thread of the MongoDB software. You can do replication with MongoDB and each replica would be an instance of MongoDB, a single running thread of the software. So if you have 4 MongoDB replicas all on one machine you'll have 4 running threads, one thread per replica. One MongoDB instance can host many databases and each database can hold many collections and each collection of course can have many records.

Yes, their can be multiple MongoDB instance all on one HOST:PORT. But at a time only one MongoDB will be running and all the CRUD operations that you are gonna perform will be with that Instance whether its some web application, mongo command line shell or anything else, all the clients making CRUD operations will be making on that specific server instance.

Now different instances have their specific Mongo Shells and databases. So the Hierarchy is Specific MongoDB instance(To start that server: Mongod and to access the Command Line shell of MongoDB: mongo) > Databases(show dbs) > collections(show collections) > fields(db.collection_name.find())

Now their is a Global MongoDB server/instance which you can start and stop using task manager>services>MongoDB which in my system is currently turned off and a different instance is running which you can see in details if other MongoDB instance is currently running

The global mongod daemon process is always running(as it's a daemon process that runs in background from start till the end of the system) but sometimes due to some error it may stop or you may stop it to start some other MongoDB instance which has different data as you can see on mongo shell from the global instance To switch to the global MongoDB instance you have to exit the mongod server and start the global server from task manager Also you don't have to start and run the Global server everytime from cmd as it's always running so you can directly access command line interface using as simple command

    mongo

on cmd.

And if by chance none of the MongoDB instance/server is running you can't access Mongo shell or perform any crud operations. So its important to first start the MongoDB server using mongod or start the Global MongoDB server from task manager.

Note You can also switch between active instances while the server is running. By simply Starting and stopping the Main MongoDB instance from task Manager.

I wish I have explained and solved most of your issues. If I have please do like this post

You should really read this document: https://www.mongodb.com/docs/manual/replication

There is nothing like a "Global" instance in MongoDB, you have PRIMARY and SECONDARY. You can read also from a SECONDARY. In general it does not make much difference whether you start the mongod service from command line or as a service.

It is really hard to give any answer to your question, because you mix up many things and actually it is not clear what you are asking!

If you try to give above as general information/advise then it would be even worse, because it is full of errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM