September 3, 2019
Bulk Operations
After the simple CRUD sample, we will show you the bulk operations from this sample, please click on this URL to play with Blogs CRUD sample.
Please see the below bulk operations with related JavaScript codes:
Features | JavaScript Codes |
Bulk Insert | db.collection(“comments”).insertMany( [ { owner_id : client.auth.user.id, date: “01/01/2018”, username: “Peter”, comment: “Testing 01”}, { owner_id : client.auth.user.id, date: “02/01/2018”, username: “Mary”, comment: “Testing 02”}, { owner_id : client.auth.user.id, date: “03/01/2018”, username: “John”, comment: “Testing 03”}, { owner_id : client.auth.user.id, date: “04/01/2018”, username: “Peter”, comment: “Testing 04”}, { owner_id : client.auth.user.id, date: “05/01/2018”, username: “John”, comment: “Testing 05”} ] ) It will insert 5 records with one single request. |
Bulk Update | db.collection(“comments”).updateMany( { username: “Peter” }, { date: “01/01/2018”, username: “Mary”, comment: “Testing 06” } ) The first part { username: “Peter” } is the filtering query, it will find all comments with username = “Peter”. The second part { date: “01/01/2018”, username: “Mary”, comment: “Testing 06” } is the updated values. All comments with username = “Peter” will be updated as date = “01/01/2018”, username = “Mary” and comment = “Testing 06”. |
Bulk Delete | db.collection(“comments”).deleteMany( { username: “Peter” } ) It will delete all comments with username = “Peter”. |