Last active
January 17, 2018 07:51
-
-
Save thanhdevapp/039b23103d0590814cc378ba0a6d59d8 to your computer and use it in GitHub Desktop.
Mongo query example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try {
db.getCollection('frontendUser').find().forEach(function(frontendUser){
db.getCollection('frontendUser').update({ _id: frontendUser._id },
{ $set: { "emailVerified": true }}
);
});
} catch (e) {
print(e);
}