Learning website Http://www.hubwiz.com/ucenter
(1) Simple insert operation
In the database, data insertion is the most basic operation in MongoDB using Db.collection.insert (document) statements to insert documents.
Documents are document data, and collection are collections of document data.
For example: All users ' information is stored in the Users collection, and each user's information is a users document, inserting data: db.users.insert (user);
If collection exists, the document is added to the collection directory. If collection does not exist, the database creates collection before saving the document. For example:
Db.person.insert ({name: "Wq", Age:12})
If you want to view the person document that you have inserted, you can use: Db.person.find () to view the data in the person collection in the current library.
If you want to see a list of collections in the current database, you can use: Show collections.
Insert statements can be inserted into a single document, as well as multiple documents at once.
When you insert multiple documents, the parameters of the Insert command are an array, and the array elements are Bson-formatted documents.
Db.person.insert ([{name: "Mary", Age:21,status: "A"},{name: "Lucy", Age:89,status: "A"},{name: "Jacky", Age:30,status: "A"}] )
DB. Collection name. Insert (BSON)
Document bulk insertion is convenient, but there are some issues to be aware of when using bulk inserts.
Because of the limitations of the Bson format, the amount of data inserted at one time cannot exceed 16M.
When inserting multiple data in an INSERT command, MONGODB does not guarantee a complete success or a complete failure.
(2) Enquiry
Db.person.find ({age:{$gt: 18}},{name:1}). Limit (2)
Db. Collection name. Find ({query condition},{return value (optional ignore secondary argument)}). Returns the number of columns
MongoDB Learning Log 1