company数据库下面heros集合里的数据:
{ "_id" : ObjectId("6100c897d0c9f4158c2b0c9b"), "name" : "贾克斯", "age" : 55, "skill" : [ "跳斩", "蓄力一击", "反击风暴", "宗师之威" ] } { "_id" : ObjectId("6100c897d0c9f4158c2b0c9c"), "name" : "易", "age" : 22, "skill" : [ "阿 尔法突袭", "冥想", "无极剑道", "高原血统" ] } { "_id" : ObjectId("6100c897d0c9f4158c2b0c9d"), "name" : "德莱厄斯", "age" : 33, "skill" : [ "大杀四方", "致残打击", "无情铁手", "诺克萨斯断头台" ] } { "_id" : ObjectId("6100c897d0c9f4158c2b0c9e"), "name" : "赵信", "age" : 40, "skill" : [ "三重爪击", "狂战怒吼", "无畏冲锋", "新月横扫" ] } { "_id" : ObjectId("6100c897d0c9f4158c2b0c9f"), "name" : "嘉文四世", "age" : 30, "skill" : [ "巨龙撞击", "黄金圣盾", "德玛西亚军旗", "天崩地裂" ] } { "_id" : ObjectId("6100c897d0c9f4158c2b0ca0"), "name" : "慎", "age" : 20, "skill" : [ "奥 义!暮临", "奥义!魂佑", "奥义!影缚", "秘奥义!慈悲度魂落" ] } >
今天的内容比较简单,主要是查询的两个限制条件 skip 和 limit
代码如下:
db.heros.find({}, { name: true, age: true, _id: false }).limit(2).skip(1*2).sort({ age: 1 });
查询结果:
{ "name" : "嘉文四世", "age" : 30 } { "name" : "德莱厄斯", "age" : 33 }
$where 修饰符:
$where操作符功能强大且灵活,它可以将JavaScript表达式的字符串或 JavaScript函数作为查询语句的一部分。在JavaScri pt表达式和函数中,可以 使用this或obj来引用当前操作的文档
具体用法如下:
> db.heros.find( {$where:"this.age >30"}, { name: true, age: true, _id: false }
) { "name" : "贾克斯", "age" : 55 } { "name" : "德莱厄斯", "age" : 33 } { "name" : "赵信", "age" : 40 } >