$ npm install mingo
For documentation on using query operators see mongodb
var Mingo = ;// or just access *Mingo* global in browser// setup the key field for your collectionMingo;// create a query with criteria// find all grades for homework with score >= 50var query =type: "homework"score: $gte: 50;
// `collection` is an Array of objects you want to query// filter collection with find()var cursor = query;// shorthand with query criteria// cursor = Mingo.find(collection, criteria);// sort, skip and limit by chainingcursor;// count matchescursor;// iterate cursor// iteration is forward onlywhile cursorconsole;// use first(), last() and all() to retrieve matched objectscursor;cursor;cursorall;// Filter non-matched objects (var result = query;
var agg ='$match': "type": "homework"'$group':'_id':'$student_id' 'score':$min:'$score''$sort':'_id': 1 'score': 1;var result = agg;// shorthandresult = Mingo;
// using Backbone.Collection as an example (any user-defined object will do)var Grades = BackboneCollection;// `collection` is an array of objectsvar grades = collection;// find students with grades less than 50 in homework or quiz// sort by score ascending and type descendingcursor = grades;// return grade with the lowest scorecursor;
The collection to mixin needs to provide a method with signature
toJSON() -> Array[Object].