Skip to content

Instantly share code, notes, and snippets.

@zolzaya
Created October 9, 2011 04:56
Show Gist options
  • Save zolzaya/1273321 to your computer and use it in GitHub Desktop.
Save zolzaya/1273321 to your computer and use it in GitHub Desktop.
> db.system.js.save({_id: "sum", value: function(x,y){return x+y;}})
> db.eval("sum(2,3);")
5
> db.numbers.save({x:4,y:2});
> db.numbers.save({x:4,y:3});
> db.numbers.save({x:3,y:3});
> db.numbers.find({$where: "sum(this.x, this.y)==6"})
{ "_id" : ObjectId("4e91283ecf719df59d2da787"), "x" : 4, "y" : 2 }
{ "_id" : ObjectId("4e91284acf719df59d2da789"), "x" : 3, "y" : 3 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment