mongo操作及相关资料
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操作及相关资料的更多相关文章
- 【mongo】聚合相关资料
一个很好的博客:http://www.cnblogs.com/shanyou/p/3494854.html 官网:https://docs.mongodb.com/manual/reference/o ...
- iOS10以及xCode8相关资料收集
兼容iOS 10 资料整理笔记 源文:http://www.jianshu.com/p/0cc7aad638d9 1.Notification(通知) 自从Notification被引入之后,苹果就不 ...
- AssetBundle机制相关资料收集
原地址:http://www.cnblogs.com/realtimepixels/p/3652075.html AssetBundle机制相关资料收集 最近网友通过网站搜索Unity3D在手机及其他 ...
- [笔记]SD卡相关资料
ESD静电放电模块 我知道的flash分为两种NOR flash和NAND flash,NOR falsh容量一般为1~16M用于单片机代码存储,NAND flash最小的是8M最大的现在听说有90G ...
- Android Notification 消息通知 相关资料.md
目录 Android Notification 消息通知 相关资料 Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题 解决方案 参考 ...
- 全文检索解决方案(lucene工具类以及sphinx相关资料)
介绍两种全文检索的技术. 1. lucene+ 中文分词(IK) 关于lucene的原理,在这里可以得到很好的学习. http://www.blogjava.net/zhyiwww/archive/ ...
- React Test相关资料
karma 前端测试驱动器,生产测试报告,多个浏览器 mocha js的测试框架,相当于junit chai,单元测试的断言库,提供expect shudl assert enzyme sinon.j ...
- Nao 类人机器人 相关资料
Nao 类人机器人 相关资料: 1.兄妹 PEPPER :在山东烟台生产,http://www.robot-china.com/news/201510/30/26564.html 2.国内机器人领先公 ...
- GBrowse配置相关资料
GBrowse配置相关资料(形状.颜色.配置.gff3) http://gmod.org/wiki/Glyphs_and_Glyph_Optionshttp://gmod.org/wiki/GBrow ...
随机推荐
- iOS正則表達式(一)
什么是正則表達式? 正則表達式是对字符串操作的一种逻辑公式. 作用? 在iOS开发中我们通常使用正則表達式来匹配给定的字符串是否符合我们的业务逻辑,比方说用户注冊帐号仅仅能是手机号或者邮箱等.我们还能 ...
- 堆叠相冊效果,兼容pc和移动端
在手机端,堆叠效果的相冊是比較常见的一种图片展示方式,每一个人的思路可能会有一些不同,实现的方法不同. 本篇博客主要是分享下我的实现方法.欢迎大家提出建议,指出我的不足,先3Q啦~ 先看一下终于的效果 ...
- How to use OpenChatter in my addon
from:https://doc.openerp.com/trunk/mail/mail_openchatter_howto/ A small my_task model will be used a ...
- eclipse no java machine vitual was found
eclipse no java machine vitual was found CreateTime--2018年4月27日10:41:20 Author:Marydon 1.错误提示 2.问题 ...
- uva 699 The Falling Leaves(建二叉树同一时候求和)
本来看着挺难的.大概是由于我多瞟了一眼题解,瞬间认为简单多了.做题就得这样,多自己想想.如今是 多校联赛,然而我并不会做. .. .慢慢来,一直在努力. 分析: 题上说了做多不会超过80行.所以能够开 ...
- 【Linux】war包的解压与压缩
现在存在一个war包test.war(以下是在Linux上操作) 1.解压war包 jar –xvf test.war 说明:直接解压到当前文件夹,如果需要解压到指定的文件夹下,需要将test.war ...
- Oracle单实例启动多个实例
Oracle多实例运行,单个实例就是一个数据库!,一个数据库对应多个实例是RAC Linux建立oracle的实例步骤: 1.在linux服务器的图形界面下,打开一个终端,输入如下的命令: xhost ...
- 【转载】MyEclipse使用指南(精简版)
1.安装 2.注册 3.配置 window ----> preferences (1)配置 JDK java--->Installed JREs --> Add ---> JR ...
- swift上传图片
import UIKit import AFNetworking class YJRequest: NSObject { //#pragma mark - 上传图片 func uploadImageW ...
- 使用自定义模板来弥补eclipse没有新建Filter的功能
http://yufei.iteye.com/blog/125012 eclipse插件,并没有为我们提供Filter的新建功能,为此我们不得不每次都去新建个类,然后输入那繁琐的重复代码,这完全就是浪 ...