mongodb与SQL常见语句对照
|
inert into users value(3,5) |
db.users.insert({a:3,b:5}) |
|
|
|
|
select a,b from users |
db.users.find({}, {a:1,b:1}) |
|
select * from users |
db.users.find() |
|
select * from users where age=33 |
db.users.find({age:33}) |
|
select a,b from users where age=33 |
db.users.find({age:33}, {a:1,b:1}) |
|
select * from users where age=33 order by name |
db.users.find({age:33}).sort({name:1}) |
|
select * from users where age>33 |
db.users.find({age:{$gt:33}}) |
|
select * from users where age!=33 |
db.users.find({age:{$ne:33}}) |
|
select * from users where name like "%Joe%" |
db.users.find({name:/Joe/}) |
|
select * from users where name LIKE "Joe%" |
db.users.find({name:/^Joe/}) |
|
select * from users where age>33 and age<=40 |
db.users.find({'age':{$gt:33,$lte:40}}) |
|
select * from users order by name desc |
db.users.find().sort({name:-1}) |
|
select * from users where a=1 and b='q' |
db.users.find({a:1,b:'q'}) |
|
select * from users limit 10 skip 20 |
db.users.find().limit(10).skip(20) |
|
select * from users where a=1 or b=2 |
db.users.find( { $or : [ { a : 1 } , { b : 2 } ] } ) |
|
select * from users limit 1 |
db.users.findOne() |
|
select order_id from orders o, order_line_items li where li.order_id=o.order_id and li.sku=12345 |
db.orders.find({"items.sku":12345},{_id:1}) |
|
select customer.name from customers,orders where orders.id="q179" and orders.custid=customer.id |
var o = db.orders.findOne({_id:"q179"}); var name = db.customers.findOne({_id:o.custid}) |
|
|
|
|
select distinct last_name from users |
db.users.distinct('last_name') |
|
select count(*y) from users |
db.users.count() |
|
select count(*y) from users where age > 30 |
db.users.find({age: {'$gt': 30}}).count() |
|
select count(age) from users |
db.users.find({age: {'$exists': true}}).count() |
|
|
|
|
create index myindexname on users(name) |
db.users.ensureIndex({name:1}) |
|
create index myindexname ON users(name,ts desc) |
db.users.ensureIndex({name:1,ts:-1}) |
|
|
|
|
explain select * from users where z=3 |
db.users.find({z:3}).explain() |
|
|
|
|
update users set a=1 where b='q' |
db.users.update({b:'q'}, {$set:{a:1}}, false, true) |
|
update users set a=a+2 where b='q' |
db.users.update({b:'q'}, {$inc:{a:2}}, false, true) |
|
|
|
|
delete from users where z="abc" |
db.users.remove({z:'abc'}); |
mongodb与SQL常见语句对照的更多相关文章
- MongoDB对应SQL语句
-------------------MongoDB对应SQL语句------------------- 1.Create and Alter 1. sql: crea ...
- SQL中常见语句
SQL中常见语句笔记: --替换字段中的回车符和换行符 ) ), '') --删除表命令 DROP TABLE [dbo].[MGoods_Test] --删除表中数据命令 DELETE FROM [ ...
- mongodb 跟踪SQL语句及慢查询收集
有个需求:跟踪mongodb的SQL语句及慢查询收集 第一步:通过mongodb自带函数可以查看在一段时间内DML语句的运行次数. 在bin目录下面运行 ./mongostat -port 端口号 ...
- mongodb 操作语句与sql操作语句对比
上行:SQL 操作语句 下行:Mongo 操作语句 CREATE TABLE USERS (a Number, b Number) db.createCollection("mycoll&q ...
- Mongodb 与 SQL 语句对照表
In addition to the charts that follow, you might want to consider the Frequently Asked Questions sec ...
- [转]MySQL 最基本的SQL语法/语句
MySQL 最基本的SQL语法/语句,使用mysql的朋友可以参考下. DDL-数据定义语言(Create,Alter,Drop,DECLARE) DML-数据操纵语言(Select,Delete ...
- SQL常见笔试面试题
sql理论题 1.触发器的作用? 答:触发器是一中特殊的存储过程,主要是通过事件来触发而被执行的.它可以强化约束,来维护数据的完整性和一致性,可以跟踪数据库内的操作从而不允许未经许可的更新和变化.可以 ...
- PL/SQL常见设置--Kevin的专栏
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- 最基本的SQL语法/语句
DDL—数据定义语言(Create,Alter,Drop,DECLARE) DML—数据操纵语言(Select,Delete,Update,Insert) DCL—数据控制语言(GRANT,REVOK ...
随机推荐
- phantomjs学习资料
http://blog.csdn.net/mecho/article/details/45888465 phantomjs的使用说明,尤其是webpage创建,资源加载前后的处理方法.
- 图像添加logo水印函数
<?php //图像添加水印函数 /** *为一张图片添加上一个logo水印(以保存新图片的方式实现) *@param string $picname 被缩放的处理图片源 *@param int ...
- Minimum Depth of Binary Tree,求树的最小深度
算法分析:递归和非递归两种方法. public class MinimumDepthofBinaryTree { //递归,树的最小深度,就是它左右子树的最小深度的最小值+1 public int m ...
- codevs 1690 开关灯 线段树+延迟标记
1690 开关灯 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description YYX家门前的街上有N(2<=N<=100000)盏路灯,在晚上六点之前,这 ...
- python 判断字典是否为空
my_dict = {} if not bool(my_dict): print("Dictionary is empty")
- Andrew and Taxi CodeForces - 1100E (思维,拓扑)
大意: 给定有向图, 每条边有一个权值, 假设你有$x$个控制器, 那么可以将所有权值不超过$x$的边翻转, 求最少的控制器数, 使得翻转后图无环 先二分转为判定问题. 每次check删除能动的边, ...
- Linux如何修改命令提示符
1.什么是命令提示符 命令提示符是CLI(command-line interface,命令行界面)在人机交互的过程中提示用户可以进行命令输入的特殊符号,在Linux中普通用户的prompt为“$”, ...
- UVA-12166 Equilibrium Mobile(二叉树)
题目大意:改变二叉树上的权值,使树平衡,问最少该几个值. 题目分析:不会做,查的题解.有条奇妙的性质:如果将第d层权值为w的节点为基准做改动,则整棵树的总重量为w<<d,即w*2^d.仔细 ...
- UVA-12657 Boxes in a Line (双向链表)
题目大意:一个1~n的升序数字序列,有4种操作.操作1,将x放到y前面一个位置:操作2将x放到y后面的一个位置:操作3交换x和y的位置:操作4反转整个序列.求经过m次操作后的所有奇数项的和. 题目分析 ...
- ssh隧道(通过跳板机)连接mysql
案例: A服务器 B服务器 C服务器mysql 现在mysql服务器C只能通过内网访问,B服务器就能通过内网连接访问到mysql A服务器无法直接连接C服务器mysql,所以要通过跳板机(跳板 ...