Methods in MongoDB
Methods in MongoDB
• If the value of the field is set to 1, the field will be displayed in the
returned document.
• If the value of the field is set to 0, the field will not be displayed in the
returned document.
2. skip():
• It is used to skip first n documents mentioned in the query.
• skip() is used with find() method.
Case 2: If save query contains “_id” field and if the document with
mentioned id already exists in the collection, then save() calls update()
method to update that existing document with fields:values given in the
query.
Case 3: If save query contains “_id” field and if the document with
mentioned id does not exist in the collection, then save() calls insert()
method to insert new document with given “_id” and fields:values.
Projection in MongoDB
1. Save a new document without specifying an _id field:
• db.student.save({rollno:10,name:”Jackson”,percentage:67})
– Here _id is not mentioned, save() will insert above document in
the collection.