MongoDB installation and use
MongoDB is a non relational database that stores data in BSON (Binary JSON) format, with high scalability and flexibility. The following will provide a detailed introduction to the installation process of MongoDB and demonstrate how to create data tables and perform data insertion, modification, query, and deletion operations.
Install MongoDB:
1. Download MongoDB: Visit the MongoDB official website( https://www.mongodb.com/ )Select the appropriate version of MongoDB for the operating system to download.
2. Install MongoDB: Unzip the downloaded files and add the binary file directory of MongoDB to the system environment variable.
Create a data table:
1. Start MongoDB: Open a terminal or command line window and execute the 'mongod' command to start the MongoDB service.
2. Connect to MongoDB: Open a new terminal or command line window, and execute the 'mongo' command to connect to MongoDB.
3. Create a database: Execute the 'use<database name>' command to create a new database, such as' use mydb '.
4. Create a data table: Execute the 'db. createCollection ('Table Name>') 'command to create a new data table, such as' db. createCollection ('users')'.
Data insertion:
1. Select a data table: Execute the 'use<database name>' command to select the database to operate on, such as' use mydb '.
2. Insert Data: Execute ` db< Table name>. insertOne (<document>) 'command inserts a piece of data, such as' db. users. insertOne ({name:' Alice ', age: 25})'.
Data modification:
1. Select a data table: Execute the 'use<database name>' command to select the database to operate on, such as' use mydb '.
2. Modify data: Execute ` db< Table Name>. updateOne (<Condition>,<Update>) 'Command to modify a piece of data, such as' db. users. updateOne ({name:'Alice'}, {$set: {age: 26}) '.
Data Query:
1. Select a data table: Execute the 'use<database name>' command to select the database to operate on, such as' use mydb '.
2. Query data: Execute ` db< Table name>. find (<condition>) 'Command to query data, such as' db. users. find ({name:' Alice '})'.
Data deletion:
1. Select a data table: Execute the 'use<database name>' command to select the database to operate on, such as' use mydb '.
2. Delete data: Execute ` db< The command '. deleteOne (<condition>)' deletes a piece of data, such as' db. users. deleteOne ({name:'Alie '})'.
The above is the basic installation and usage introduction of MongoDB. Through these operations, data insertion, modification, query, and deletion can be achieved.