Mongo
Show DBS View all databases
Using use, you can switch the database, and if there is no database, create a new
Use local to switch down the local database
Add data
Db.test.insert ({name: "Jack"}) inserts a piece of data into the test table, and if no test table is created, it is inserted in bulk if an array of documents is passed in.
BULK INSERT
Db.test.batchInsert ([{"_id": 0, "_id": 1}]) accepts an array of documents as a parameter, and if a document insertion fails during insertion, the document is inserted successfully before it and the document is not inserted.
After 3.4, I changed it.
Db.test.insertMany ()
Delete data
Db.test.remove ({name: "Jack"}) Delete all data in the test table named Jack
Find data
Db.test.find () View all data in test table
Db.test.findOne () View a single piece of data
modifying data
Db.test.update ({name: "Jack"}, {name: "Mike"}) change the data named Jack in the test table to name equals Mike
Db.test.save ({name: "Alice"}) creates a new data without the data, and then updates the
Linux creates a. Mongorc.js in the current user's home directory (/HOME/XXX).
MONGO the file is loaded before running the shell
You can override delete operations in a file to avoid deleting data
You can edit the variables in the shell after you specify editor= "/usr/bin/vim"
You can use a for loop to traverse the data in the shell
var collections = ["A", "B", "C"] for (var in collections) { print ( Collections[i])}
A lot of the content has changed, please check the Official document address http://docs.mongoing.com/manual-zh/mongo.html
MongoDB's authoritative guide to MongoDB basic Knowledge learning record