Simple and useful mongodb-insert operation

Source: Internet
Author: User

Insert data:

MongoDB uses the Insertone function to insert a single piece of data

Such as:

1. First specify the inserted data with document:

Document = ({"Type": "Book", "Title": "Definitive Guide to MongoDB 3rd ed.", "ISBN": "978-1-4842-1183-0", "Publisher": " Apress "," Author ": [" Hows,david "," Plugge,eelco "," Membrey,peter "," Hawkins,tim "]})

System returns

"Type": "Book",
"Title": "Definitive Guide to MongoDB 3rd ed.",
"ISBN": "978-1-4842-1183-0",
"Publisher": "Apress",
"Author": [

2. Perform the insert operation: (document)

System returns:

"acknowledged": true,
"Insertedid": ObjectId ("5aa47c1953350e04ddbd6fa3")

Wherein, Insertedid is inserted after the formation of the _ID key value, guaranteed uniqueness, it consists of 4-bit timestamp 3-bit machine ID 2-bit Process ID 3-bit counter composition

There is also a way to insert data directly through the shell

such as: ({"Type": "CD", "Artist": "Nirvana", "Title": "Nevermind", "tracklist": [{"Track": "1", "Titie": " Smells like Teen Spirit "," Length ": ' 5:02 '},{' track ':" 2 "," Title ":" In Bloom "," Length ":" 4:15 "}]})

System returns:

"acknowledged": true,
"Insertedid": ObjectId ("5AA47DD553350E04DDBD6FA4")

Simple and useful mongodb-insert operation

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: 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.