Skip to content

Instantly share code, notes, and snippets.

@DarshanKumar89
Last active September 27, 2020 15:35
Show Gist options
  • Save DarshanKumar89/169a5b2dc8664224453e1955da15b86f to your computer and use it in GitHub Desktop.
Save DarshanKumar89/169a5b2dc8664224453e1955da15b86f to your computer and use it in GitHub Desktop.
Mongodb: delete all users in collection except three users in Mongodb / bulk update collection by key

remove query in mongodb

db.user.remove({ "email" : {$nin:["[email protected]","[email protected]","[email protected]"] }});

example 2

db.collectionids.remove({ "userId" : {$nin: ["5f589b6a99c1ce5e45434d5a","5f58cdd699c1ce5e45434d68","5f58d1e799c1ce5e45434d69"] }});

=================================================== bulk update query in mongodb

var bulk = db.user.initializeUnorderedBulkOp();
bulk.find( { accountPasswordConfirmStatus: "false" } ).update( { $set: { accountPasswordConfirmStatus: "true" } } );
bulk.execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment