MongoDB Learning Log 1

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.