Mongodb对应sql操作

来源:未知 责任编辑:责任编辑 发表时间:2013-11-18 20:57 点击:

Mongodb对应sql操作
 
SQL Statement 
Mongo Statement 
CREATE TABLE USERS (a Number, b Number) 
implicit; can also be done explicitly with 
db.createCollection("mycoll") 
ALTER TABLE users ADD ... 
implicit 
 
INSERT INTO USERS VALUES(3,5) 
db.users.insert({a:3,b:5}) 
  www.2cto.com  
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   www.2cto.com  
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) 
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Request.ServerVariables 参数大全
  • 执行全文索引时出现权限不足的解决方法
  • 导入excel文件处理流程节点的解决方案
  • 查看sql修改痕迹(SQL Change Tracking on Table)
  • MongoDB安装为Windows服务方法与注意事项
  • App数据层设计及云存储使用指南
  • PostgreSQL启动过程中的那些事三:加载GUC参数
  • 写给MongoDB开发者的50条建议Tip1
  • Percolator与分布式事务思考(二)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1