Skip to content

Instantly share code, notes, and snippets.

@jeffdonthemic
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffdonthemic/7464db913072ee01ea5e to your computer and use it in GitHub Desktop.
Save jeffdonthemic/7464db913072ee01ea5e to your computer and use it in GitHub Desktop.
Mongo Query Examples
// find one record with the hightest value
User.find({}).sort({goldenTicket: 'descending'}).limit(1).exec(function(err, items) {
if (!items[0].goldenTicket) {
deferred.resolve(1000);
} else {
deferred.resolve(items[0].goldenTicket + 1);
}
});
// choose a random problem and return it
Problem.count(function(err, ct) {
var r = Math.floor(Math.random() * ct);
Problem.find({ event: 'tco14' }).limit(1).skip(r).exec(function(err, problem) {
console.log(problem);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment