mongodb与sql语句对比
- 左边是mongodb查询语句,右边是sql语句。对照着用,挺方便。
- db.users.find() select * from users
- db.users.find({"age" : 27}) select * from users where age = 27
- db.users.find({"username" : "joe", "age" : 27}) select * from users where "username" = "joe" and age = 27
- db.users.find({}, {"username" : 1, "email" : 1}) select username, email from users
- db.users.find({}, {"username" : 1, "_id" : 0}) // no case // 即时加上了列筛选,_id也会返回;必须显式的阻止_id返回
- db.users.find({"age" : {"$gte" : 18, "$lte" : 30}}) select * from users where age >=18 and age <= 30 // $lt(<) $lte(<=) $gt(>) $gte(>=)
- db.users.find({"username" : {"$ne" : "joe"}}) select * from users where username <> "joe"
- db.users.find({"ticket_no" : {"$in" : [725, 542, 390]}}) select * from users where ticket_no in (725, 542, 390)
- db.users.find({"ticket_no" : {"$nin" : [725, 542, 390]}}) select * from users where ticket_no not in (725, 542, 390)
- db.users.find({"$or" : [{"ticket_no" : 725}, {"winner" : true}]}) select * form users where ticket_no = 725 or winner = true
- db.users.find({"id_num" : {"$mod" : [5, 1]}}) select * from users where (id_num mod 5) = 1
- db.users.find({"$not": {"age" : 27}}) select * from users where not (age = 27)
- db.users.find({"username" : {"$in" : [null], "$exists" : true}}) select * from users where username is null // 如果直接通过find({"username" : null})进行查询,那么连带"没有username"的纪录一并筛选出来
- db.users.find({"name" : /joey?/i}) // 正则查询,value是符合PCRE的表达式
- db.food.find({fruit : {$all : ["apple", "banana"]}}) // 对数组的查询, 字段fruit中,既包含"apple",又包含"banana"的纪录
- db.food.find({"fruit.2" : "peach"}) // 对数组的查询, 字段fruit中,第3个(从0开始)元素是peach的纪录
- db.food.find({"fruit" : {"$size" : 3}}) // 对数组的查询, 查询数组元素个数是3的记录,$size前面无法和其他的操作符复合使用
- db.users.findOne(criteria, {"comments" : {"$slice" : 10}}) // 对数组的查询,只返回数组comments中的前十条,还可以{"$slice" : -10}, {"$slice" : [23, 10]}; 分别返回最后10条,和中间10条
- db.people.find({"name.first" : "Joe", "name.last" : "Schmoe"}) // 嵌套查询
- db.blog.find({"comments" : {"$elemMatch" : {"author" : "joe", "score" : {"$gte" : 5}}}}) // 嵌套查询,仅当嵌套的元素是数组时使用,
- db.foo.find({"$where" : "this.x + this.y == 10"}) // 复杂的查询,$where当然是非常方便的,但效率低下。对于复杂查询,考虑的顺序应当是 正则 -> MapReduce -> $where
- db.foo.find({"$where" : "function() { return this.x + this.y == 10; }"}) // $where可以支持javascript函数作为查询条件
- db.foo.find().sort({"x" : 1}).limit(1).skip(10); // 返回第(10, 11]条,按"x"进行排序; 三个limit的顺序是任意的,应该尽量避免skip中使用large-number
mongodb与sql语句对比的更多相关文章
- MongoDB对应SQL语句
-------------------MongoDB对应SQL语句------------------- 1.Create and Alter 1. sql: crea ...
- mongodb 跟踪SQL语句及慢查询收集
有个需求:跟踪mongodb的SQL语句及慢查询收集 第一步:通过mongodb自带函数可以查看在一段时间内DML语句的运行次数. 在bin目录下面运行 ./mongostat -port 端口号 ...
- mongodb查询语句与sql语句对比
左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * from users db.users.find({"age" ...
- Mongodb 与sql 语句对照
此处用mysql中的sql语句做例子,C# 驱动用的是samus,也就是上文中介绍的第一种. 引入项目MongoDB.dll //创建Mongo连接 var mongo = new Mongo(&qu ...
- Mongodb 与 SQL 语句对照表
In addition to the charts that follow, you might want to consider the Frequently Asked Questions sec ...
- mongodb的查询方式与sql语句对比
下面是sql和Mongodb对应的一些语法: SQL Statement Mongo Query Language Statement CREATE TABLE USERS (a Number, b ...
- mongodb与sql语句对照表
inert into users value(3,5) db.users.insert({a:3,b:5}) select a,b from users db.users.find({}, { ...
- MySQL与MongoDB之SQL语法对比
- mongodb的sql日志
在Yii2中是没有打印出mongodb的sql语句,故借用下log来查看吧. 在网上有说可以使用$model->find()->createCommand()->getRawSql( ...
随机推荐
- vs2010编译C++ 友元函数
// CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...
- 【Winform】ProgressBar
var progressBar1 = new System.Windows.Forms.ProgressBar(); ; progressBar1.Maximum = ; progressBar1.V ...
- 2-10 就业课(2.0)-oozie:10、伪分布式环境转换为HA集群环境
hadoop 的基础环境增强 HA模式 HA是为了保证我们的业务 系统 7 *24 的连续的高可用提出来的一种解决办法,现在hadoop当中的主节点,namenode以及resourceManager ...
- oracle的存储过程和函数有什么区别?
Oracle中的函数与存储过程的区别: A:函数必须有返回值,而过程没有. B:函数可以单独执行.而过程必须通过execute执行. C:函数可以嵌入到SQL语句中执行.而过程不行. 其实我 ...
- 008、MySQL日期时间格式化输出
#日期格式化 SELECT date_format( '2008/08/08 22:23:01', '%Y-%m-%d-%H--%i--%s' ); 不忘初心,如果您认为这篇文章有价值,认同作者的付出 ...
- word中替换内容
参考了一篇文章 然后做了如下修改 用python的win32com模块替换word中的文字搞定批量打印奖状 python 操作 office python操作word # -*- coding: u ...
- Oracle之SQL优化专题03-如何看懂SQL的执行计划
专题第一篇<Oracle之SQL优化专题01-查看SQL执行计划的方法>讲到了查看SQL执行计划的方法,并介绍了各种方法的应用场景,那么这一篇就主要介绍下如何看懂SQL的执行计划.毕竟如果 ...
- 吴裕雄--天生自然C++语言学习笔记:C++ 判断
判断结构要求程序员指定一个或多个要评估或测试的条件,以及条件为真时要执行的语句(必需的)和条件为假时要执行的语句(可选的). 下面是大多数编程语言中典型的判断结构的一般形式: 判断语句 if 语句 一 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-italic
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- SciKit-Learn 使用matplotlib可视化数据
章节 SciKit-Learn 加载数据集 SciKit-Learn 数据集基本信息 SciKit-Learn 使用matplotlib可视化数据 SciKit-Learn 可视化数据:主成分分析(P ...