0% found this document useful (0 votes)
7 views1 page

MongoDB Notes

The document outlines various MongoDB operations for sorting, grouping, and deleting documents. It details how to retrieve the first and last document from a sorted result, as well as methods for deleting single or multiple documents using remove(), deleteOne(), and deleteMany(). Additionally, it mentions the findOneAndDelete() function for deleting a document based on specific criteria.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

MongoDB Notes

The document outlines various MongoDB operations for sorting, grouping, and deleting documents. It details how to retrieve the first and last document from a sorted result, as well as methods for deleting single or multiple documents using remove(), deleteOne(), and deleteMany(). Additionally, it mentions the findOneAndDelete() function for deleting a document based on specific criteria.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

First : Return the name of the first document in the sorted result.

Last : Return the name of the last document in the sorted result.

Query : db.mycol1.aggregate([{$sort:{age:1}},{$group:{_id:null,youngest:
{$first:"$name"},oldest:{$last:"$name"}}}]);

In operator : checking the condition more than one at a time;

!!!!
===================================================================================
===========================================!!!

DELETING THE DOCUMENT :

=> remove()
=> deleteOne()
=> deleteMany()

creating functions : db.createCollection("programmers");

Creating data : db.programmers.insert([{name:"james"},{name:"dennis"},


{name:"kumar"}]);

deleteOne() : db.programmers.deleteOne({name:{$in:
["azar","james","dennis"]}}); ///it will delete james

DeleteMany() : db.programmers.deleteMany({name:{$in:["azar","james","dennis"]}});

Remove() : db.programmers.remove({name:"james"});

DeleteMany : db.programmers.deleteMany({age:{$gt:60}});

FINDANDDELETE():

=> used to delete one single document based on selection criteria.


=> it deletes the first documents from the collection that matches the
given filter query expression.

=> db.mycol.findOneAndDelete({name:"kishore"});

You might also like