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. Python编程-Office操作-操作Excel(上)

    首先,需要安装openpyxl库 http://openpyxl.readthedocs.org/en/default/ pyton 2.xpip install openpyxl python 3. ...

  2. JavaScript简述一

    一.什么时JavaScript JavaScript是一种具有面向对象能力的,解释型的设计语言,更具体一点,它是基于圣明和事件驱动并具有相对安全必的客户端脚本语言,因为它不需要在一个语言环境下运行,只 ...

  3. 【SPSS】软件介绍

    SPSS软件是美国斯坦福大学三位学生1968年研制开发的统计软件,SPSS是Statistical Package for Social Science(社会科学软件统计包)的缩写,2000年SPSS ...

  4. ASP.NET MVC:通过FileResult向浏览器发送文件

    在 Controller 中我们可以使用 FileResult 向客户端发送文件. FileResult FileResult 是一个抽象类,继承自 ActionResult.在 System.Web ...

  5. LINUX下一款不错的网站压力测试工具webbench

    LINUX下一款不错的网站压力测试工具webbench 分类: Linux 2014-07-03 09:10 220人阅读 评论(0) 收藏 举报 [html] view plaincopy wget ...

  6. Android 华为U8818真机调试 无法打印Logcat

    摘抄至:http://blog.csdn.net/studyalllife/article/details/8558258 在我们使用真机进行Android应用调试时,无法获得调试信息,错误提演示样例 ...

  7. python标准日志模块logging的使用方法

    参考地址 最近写一个爬虫系统,需要用到python的日志记录模块,于是便学习了一下.python的标准库里的日志系统从Python2.3开始支持.只要import logging这个模块即可使用.如果 ...

  8. 【laravel54】如果开启了自带的时间戳(Y-h-m H:s:m),getInsertId一定要手动加上created_at 和 updated_at字段填充

    [laravel54]如果开启了自带的时间戳(Y-h-m H:s:m),getInsertId一定要手动加上created_at 和 updated_at字段填充

  9. TP3.2之引入第三方类库文件和普通.php文件

    1.引入第三方类库 .class.php文件 1.1 类库有写namespace命名空间 namespace Org\Util; class Auth { } 保存到ThinkPHP/Library/ ...

  10. .NET的多种事务处理

    Oracle 的事务操作,有时候想在批量操作数据集合的时候,执行一次失败,即为了避免数据异常,将所有的操作回滚..NET给我们提供了良好的事务操作,Oracle端也有事务操作,可以灵活使用,此处介绍. ...