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": [
"Hows,david",
"Plugge,eelco",
"Membrey,peter",
"Hawkins,tim"
]
}
2. Perform the insert operation:
Db.media.insertOne (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: Db.media.insertOne ({"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