JavaScript实现MongoDB查询语言:Mingo
Mingo是MongoDB查询语言的JavaScript实现。
安装
$ npm install mingo
在浏览器中
<!-- DO NOT FORGET Underscore --> <script type="text/javascript" src="./underscore-min.js"></script> <script type="text/javascript" src="./mingo-min.js"></script>
特性
- 比较操作符($gt, $gte, $lt, $lte, $ne, $nin, $in)
- 逻辑操作符 Operators ($and, $or, $nor, $not)
- Evaluation Operators ($regex, $mod, $where)
- 数组操作符 ($all, $elemMatch, $size)
- Element Operators ($exists, $type)
- Aggregation Pipeline Operators ($group, $match, $project, $sort, $limit, $unwind, $skip)
- Conditional Operators ($cond, $ifNull)
- Group Operators ($addToSet, $sum, $max, $min, $avg, $push, $first, $last)
- Arithmetic Operators ($add, $divide, $mod, $multiply, $subtract)
- String Operators ($cmp, $strcasecmp, $concat, $substr, $toLower, $toUpper)
- Set Operators ($setEquals, $setIntersection, $setDifference, $setUnion, $setIsSubset, $anyElementTrue, $allElementsTrue)
- Projection Operators ($elemMatch, $slice)
- JSON stream filtering and projection. NodeJS only
var Mingo = require('mingo'); // or just access *Mingo* global in browser // setup the key field for your collection Mingo.setup({ key: '_id' // default }); // create a query with criteria // find all grades for homework with score >= 50 var query = new Mingo.Query({ type: "homework", score: { $gte: 50 } });搜索与过滤
// filter collection with find() var cursor = query.find(collection); // shorthand with query criteria // cursor = Mingo.find(collection, criteria); // sort, skip and limit by chaining cursor.sort({student_id: 1, score: -1}) .skip(100) .limit(100); // count matches cursor.count(); // iterate cursor // iteration is forward only while (cursor.hasNext()) { console.log(cursor.next()); } // use first(), last() and all() to retrieve matched objects cursor.first(); cursor.last(); cursor.all(); // Filter non-matched objects ( var result = query.remove(collection);
项目主页:http://www.open-open.com/lib/view/home/1422276537734
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!