mongo操作 
find方法 db.collection_name.find(); 查询所有的结果: select * from users; db.users.find(); 指定返回那些列(键): select name, skills from users; db.users.find({}, {'name' : 1, 'skills' : 1}); 补充说明: 第一个{} 放where条件 第二个{} 指定那些列显示和不显示 (0表示不显示 1表示显示) where条件: 1.简单的等于: select name, age, skills from users where name = 'hurry'; db.users.find({'name' : 'hurry'},{'name' : 1, 'age' : 1, 'skills' : 1}); 2.使用and select name, age, skills from users where name = 'hurry' and age = 18; db.users.find({'name' : 'hurry', 'age' : 18},{'name' : 1, 'age' : 1, 'skills' : 1}); 3.使用or select name, age, skills from users where name = 'hurry' or age = 18; db.users.find({ '$or' : [{'name' : 'hurry'}, {'age' : 18}] },{'name' : 1, 'age' : 1, 'skills' : 1}); 4.<, <=, >, >= ($lt, $lte, $gt, $gte ) select * from users where age >= 20 and age <= 30; db.users.find({'age' : {'$gte' : 20, '$lte' : 30}}); 5.使用in, not in ($in, $nin) select * from users where age in (10, 22, 26); db.users.find({'age' : {'$in' : [10, 22, 26]}}); 6.匹配null select * from users where age is null; db.users.find({'age' : null); 7.like (mongoDB 支持正则表达式) select * from users where name like "%hurry%"; db.users.find({name:/hurry/}); select * from users where name like "hurry%"; db.users.find({name:/^hurry/}); 8.使用distinct select distinct (name) from users; db.users.distinct('name'); 9.使用count select count(*) from users; db.users.count(); 10.数组查询 (mongoDB自己特有的) 如果skills是 ['java','python'] db.users.find({'skills' : 'java'}); 该语句可以匹配成功 $all db.users.find({'skills' : {'$all' : ['java','python']}}) skills中必须同时包含java 和 python $size db.users.find({'skills' : {'$size' : 2}}) 遗憾的是$size不能与$lt等组合使用 $slice db.users.find({'skills' : {'$slice : [1,1]}}) 两个参数分别是偏移量和返回的数量 11.查询内嵌文档 12.强大的$where查询 db.foo.find();
{ "_id" : ObjectId("4e17ce0ac39f1afe0ba78ce4"), "a" : 1, "b" : 3, "c" : 10 }
{ "_id" : ObjectId("4e17ce13c39f1afe0ba78ce5"), "a" : 1, "b" : 6, "c" : 6 } 如果要查询 b = c 的文档怎么办? > db.foo.find({"$where":function(){ for(var current in this){
for(var other in this){
if(current != other && this[current] == this[other]){
return true;
}
}
}
return false; }}); { "_id" : ObjectId("4e17ce13c39f1afe0ba78ce5"), "a" : 1, "b" : 6, "c" : 6 } 相关链接:

http://www.cnblogs.com/lipan/archive/2011/03/08/1966463.html

http://fuliang.iteye.com/blog/607359

http://www.cnblogs.com/cxd4321/archive/2011/06/24/2089051.html

http://www.cnblogs.com/cxd4321/archive/2011/06/24/2089057.html

http://blog.csdn.net/yczz/article/details/5972624

mongo操作及相关资料的更多相关文章

  1. 【mongo】聚合相关资料

    一个很好的博客:http://www.cnblogs.com/shanyou/p/3494854.html 官网:https://docs.mongodb.com/manual/reference/o ...

  2. iOS10以及xCode8相关资料收集

    兼容iOS 10 资料整理笔记 源文:http://www.jianshu.com/p/0cc7aad638d9 1.Notification(通知) 自从Notification被引入之后,苹果就不 ...

  3. AssetBundle机制相关资料收集

    原地址:http://www.cnblogs.com/realtimepixels/p/3652075.html AssetBundle机制相关资料收集 最近网友通过网站搜索Unity3D在手机及其他 ...

  4. [笔记]SD卡相关资料

    ESD静电放电模块 我知道的flash分为两种NOR flash和NAND flash,NOR falsh容量一般为1~16M用于单片机代码存储,NAND flash最小的是8M最大的现在听说有90G ...

  5. Android Notification 消息通知 相关资料.md

    目录 Android Notification 消息通知 相关资料 Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题 解决方案 参考 ...

  6. 全文检索解决方案(lucene工具类以及sphinx相关资料)

    介绍两种全文检索的技术. 1.  lucene+ 中文分词(IK) 关于lucene的原理,在这里可以得到很好的学习. http://www.blogjava.net/zhyiwww/archive/ ...

  7. React Test相关资料

    karma 前端测试驱动器,生产测试报告,多个浏览器 mocha js的测试框架,相当于junit chai,单元测试的断言库,提供expect shudl assert enzyme sinon.j ...

  8. Nao 类人机器人 相关资料

    Nao 类人机器人 相关资料: 1.兄妹 PEPPER :在山东烟台生产,http://www.robot-china.com/news/201510/30/26564.html 2.国内机器人领先公 ...

  9. GBrowse配置相关资料

    GBrowse配置相关资料(形状.颜色.配置.gff3) http://gmod.org/wiki/Glyphs_and_Glyph_Optionshttp://gmod.org/wiki/GBrow ...

随机推荐

  1. Linux c 管道文件-进程间的通信 mkfifo、pipe

    管道文件: 1.       创建管道mkfifo(命名管道) #include<sys/stat.h> int mkfifo( const  char  *pathname, mode_ ...

  2. POJ 1436 Horizontally Visible Segments (线段树&#183;区间染色)

    题意   在坐标系中有n条平行于y轴的线段  当一条线段与还有一条线段之间能够连一条平行与x轴的线不与其他线段相交  就视为它们是可见的  问有多少组三条线段两两相互可见 先把全部线段存下来  并按x ...

  3. mac 安装升级python3

    如果没有安装过python3的话那就直接下载dmg文件安装升级,一般下载安装后的路径为 /Library/Frameworks/Python.framework/Versions 如果同时安装了多个p ...

  4. 很不错标签云js插件

    在蓝色看到有需要标签云的球形效果,我记得之前在网上见到过,印象比较深刻,就找出地址发给他了,接下来却还有人需要这个效果的JQuery插件,网上好像也有,但是我看现在这个就不错,就想想自己改成jquer ...

  5. cordova 命令行打包apk

    Cordova 打包 Android release app 过程详解: 1.全局安装Cordova CLI: npm install -g cordova 2.创建项目: cordova creat ...

  6. LDA主题模型浅析

    上个月参加了在北京举办SIGKDD国际会议,在个性化推荐.社交网络.广告预测等各个领域的workshop上都提到LDA模型,感觉这个模型的应用挺广泛的,会后抽时间了解了一下LDA,做一下总结: (一) ...

  7. Loadrunner脚本编程(1)-大体思路

    http://www.360doc.com/content/10/0806/13/1698198_44076570.shtml 就目前的了解.Loadrunner的脚本语言其实和C没什么区别.他内部的 ...

  8. pythong 中的 __call__

    python __call__ (可调用对象) __call__ Python中有一个有趣的语法,只要定义类型的时候,实现__call__函数,这个类型就成为可调用的. 换句话说,我们可以把这个类型的 ...

  9. iOS支付宝支付集成

    概述 iOS支付宝支付集成 详细 代码下载:http://www.demodashi.com/demo/10729.html 支付宝和微信都是业界的老大哥,相信大家都有所觉得文档.SDK都是各种坑吧( ...

  10. aop:declare-parents注解

    http://www.blogjava.net/jackfrued/archive/2010/02/27/314060.html <aop:aspect> <aop:declare- ...