Introduction to MongoDB CommandsMongoDB is a cross-platform, document-oriented, open source that provides, high availability, high performance, and easy scalability. It is one of the NoSQL databases, highly used for big data applications and other complex job processing for the data that doesn’t go well with the relational database. Instead of using the relational database concept of storing data in the form of the table, MongoDB architecture is made up of collections and documents. Here we discuss the MongoDB commands. Why MongoDB Commands?.
It can easily control the data which is placed globally, ensuring fast performance and compliance. It provides a flexible data model. This goes with the case, where the app needs to be built from scratch or the case of updating a single record.
Restarting and Stopping MongoDB Service. The MongoDB service starts automatically after you successfully install it on your machine. In some particular situations, you may want to manually stop the MongoDB service and then restart it, see the following sections for reference. Enter the crontab -e command on the command line.
No downtime, if the application is scaled.Features:. MongoDB command uses a master-slave replication concept. To prevent database downtime, this replica feature is proved to be a very important feature. This database can run over multiple servers; hence data is duplicated over multiple servers. The result of which it’s a great advantage in case of hardware failure. MongoDB command comes with the auto-sharding feature, in which process distributes data across multiple physical partitions known as shards. The result of which automatic load balancing happens.
It’s schema-less. Hence more efficient.Basic Of MongoDB Commands 1. Create DatabaseIn MongoDB use, DATABASENAME is used to create a database. If this name database doesn’t exist, it will get created, else it will return the existed one.
Web development, programming languages, Software testing & othersTo check the current database now:By default, MongoDB command comes with database name “test”. Suppose you inserted a document without specifying the database, it will automatically be stored in “test” database. Drop DatabaseIf the database is not specified, then it will delete the default database that is “test”. Create CollectionTo create collection, the MongoDB command used is: db.createCollection(name, options)Here, the name is the name of the collection & options is a document which is used to specify the configuration of the collection. Though “Options” parameter is optional, it’s good to provide it.
Drop Collection5. Insert DocumentInsert or save method is used to insert data into a collection of any database.
Ssh -t INSTANCEIP mongo:expose public-database 8 0Which yields the following output: - Service public-database exposed on port(s) container-host: 27017-8-9-7-20020Which means the MongoDB ports 27017, 27018, 27019 and 28017 were exposed at the server’s 20017, 20018, 20019, 20020 ports respectively.