Bulk.find.removeOne()
On this page
Tip
Starting in version 3.2, MongoDB also provides the db.collection.bulkWrite() method for performing bulk write operations.
Description
Bulk.find.removeOne()-
Starting in
mongosh0.12.2,Bulk.find.removeOne()is an alias forBulk.find.deleteOne().In new code, use
Bulk.find.deleteOne()instead ofBulk.find.removeOne().
Example
Create the music collection:
db.music.insertMany( [ { artist: "DOA", genre: "punk" }, { artist: "Rick Astley", genre: "pop" }, { artist: "Black Flag", genre: "punk" }, { artist: "Justin Bieber", genre: "pop" } ] )
The following example:
-
Initializes a
Bulk()operations builder. -
Searches for the genre
pop. -
Deletes
Rick Astley, the first matching pop artist, from the collection.
var bulk = db.music.initializeOrderedBulkOp(); bulk.find( { "genre": "pop" } ).removeOne(); bulk.execute()