Skip to content

Instantly share code, notes, and snippets.

@thanhdevapp
Last active January 17, 2018 07:51
Show Gist options
  • Save thanhdevapp/039b23103d0590814cc378ba0a6d59d8 to your computer and use it in GitHub Desktop.
Save thanhdevapp/039b23103d0590814cc378ba0a6d59d8 to your computer and use it in GitHub Desktop.
Mongo query example
try {
function getNextSequenceValue(sequenceName){
var sequenceDocument = db.getCollection('counters').findAndModify({
query:{_id: sequenceName },
update: {$inc:{sequence_value:1}},
new:true
});
return sequenceDocument.sequence_value;
}
db.getCollection('tree').find().forEach(function(tree){
db.getCollection('tree').update({ _id: tree._id },
{ $set: { "orderId": NumberInt(getNextSequenceValue('TreeId')) }}
);
});
} catch (e) {
print(e);
}
@thanhdevapp
Copy link
Author

try {

db.getCollection('frontendUser').find().forEach(function(frontendUser){
db.getCollection('frontendUser').update({ _id: frontendUser._id },
{ $set: { "emailVerified": true }}
);
});

} catch (e) {
print(e);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment