Here's a record of what MongoDB often commands
Database related
Create a database
Use database_name
If the database does not exist, create the database, or switch to the specified database.
Delete database : Switch to the database you want to delete, execute the command.
Db.dropdatabase ()
View all databases
Show DBS
Collection related
View all Collections
Show tables
Delete the specified collection : Replace the collection_name of the following command with the execution
Db. collection_name. Drop ()
Document related
Insert Document
Db. Collection_name.insert (document)
Insert document You can also use the Db.col.save command. If you do not specify the _id field, the Save () method is similar to the Insert () method. If the _id field is specified, the data for the _id is updated.
Update document
db.collection.update ( <query>, <update>, { < Boolean>, <boolean>, <document> })
Parameter description:
- Query: The search condition for update, similar to where in SQL update query.
- Update: Update object and some updated operators (such as $, $inc ... ) can also be understood as the SQL update query within the set after the
- upsert : Optional, this parameter means that if there is no record of update, insert objnew,true as INSERT, default is False, do not insert.
- multi : Optional, mongodb default is False, only update the first record found, if this parameter is true, will be found on the condition of a number of records update all.
- writeconcern : Optional, throws an exception level.
Delete a document
db.collection.remove ( <query>, { <boolean>, <document> })
Parameter description:
- query : (optional) The condition of the deleted document.
- justone : (optional) If set to TRUE or 1, only one document is deleted.
- Writeconcern : (optional) the level at which the exception is thrown.
Querying documents
Db.collection.find (query, projection)
Parameter description:
- query: Optional, use the query operator to specify the criteria
- projection : Optional, use the projection operator to specify the returned key. Returns all the key values in the document when queried, just omit the argument (omitted by default).
MongoDB Learning notes-common commands