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 ...
随机推荐
- php 内置函数JSON处理
一:生成json数据 <?php $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_enco ...
- 【剑指offer】二分查找二维数组
1 2 3 4 5 6 7 8 9 3 3 1 2 3 4 5 6 7 8 9 10 3 3 12 2 3 4 5 6 7 8 9 10 例子输出: Yes No No 时间限制:1 秒 内存限制:3 ...
- sqlserver2008r2安装
- java发送email(含代理方式,ssl方式,传统方式)
package spring.vhostall.com; import java.security.Security; import java.util.Date; import java.util. ...
- 〖Linux〗build sqlite3 for Arm
Version: sqlite-autoconf-3080100.tar.gz Download: https://www.sqlite.org/download.html 1. toolchains ...
- webservice系统学习笔记8-简单的权限校验
服务端handler.java package com.ws01; import java.util.Set; import javax.xml.namespace.QName; import jav ...
- centos/rhel最小化安装图形化
图形化,一般不再服务器中安装.为了提升系统的利用率. centos的yum源对应centos的源 RHEL的yum源对应RHEL的源 我演示的Centos6.5,我挂载的RHEL6.5的源.作为软件源 ...
- VS:"64位调试操作花费的时间比预期要长"的一解决途径
解决办法之一: 在命令提示符那里打入如下命令: netsh winsock reset catalognetsh int ip reset reset.log hit 重启电脑后,即可
- 【LeetCode】124. Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...
- CentOS上搭建Nginx + Mono 运行 asp.net[转]
http://www.linuxdot.net/ http://www.cnblogs.com/wander1129/archive/2011/12/16/mono.html 安装步骤: 一.获取开源 ...