June 2018
Intermediate to advanced
348 pages
8h 19m
English
To insert a document, first we specify the collection name and pass the JSON document by calling the insert method as the following syntax:
> db.collection_name.insert(JSON_Object)
Let's insert the first team to our teams collection:
> db.teams.insert({"code": "PER", ... "name": "Peru", ... "ranking": 11, ... "captain": "Paolo Guerreo", ... "Trainer": "Ricardo Gareca", ... "confederation": "Conmebol"})WriteResult({ "nInserted" : 1 })
If the insertion was executed correctly, you should receive the writeResult response that contains the number of documents inserted into its nInserted property.
Read now
Unlock full access