您好,UncleToo欢迎您!  为了更好的浏览本站,请使用高版本浏览器
RSS  Tag     设为首页 | 加入收藏
 您所在的位置:首页 > 数据库技术 > NoSQL

MongoDB语句与SQL语句对应关系表

作者:未知  来源:互联网  日期:2014-05-21 7:48:45
收藏  评论:( 0 )  阅读:419

1.select

SQL 命令MongoDB 命令
Select * FROM usersdb.users.find()
Select id, user_id, status FROM usersdb.users.find( { }, { user_id:1,status:1 } )
Select user_id,status FROM usersdb.users.find( { }, { user_id:1,status:1,_id:0 } )
Select * FROM users Where status="A"db.users.find( { status:"A" } )
Select user_id,status FROM users Where status="A"db.users.find( { status:"A" }, { user_id:1,status:1,_id:0 } )
Select * FROM users Where status!="A"db.users.find( { status: {$ne:"A" } } )
Select * FROM users Where status="A" AND age=50db.users.find( { status:"A", age:50 } )
Select * FROM users Where status="A" or age=50db.users.find( { $or: [ {status:"A" } , { age:50 } ] } )
Select * FROM users Where age>25db.users.find( { age: {$gt:25 } } )
Select * FROM users Where age<25db.users.find( { age: {$lt:25 } } )
Select * FROM users Where age>25 AND  age<=50db.users.find( { age: {$gt:25,$lte:50 } } )
Select * FROM users Where user_id like "%bc%"db.users.find( {user_id:/bc/ } )
Select * FROM users Where user_id like "bc%"db.users.find( {user_id:/^bc/ } )
Select * FROM users Where status="A" orDER BY user_id ASCdb.users.find( {status:"A" } ).sort( {user_id:1 } )
Select * FROM users Where status="A" orDER BY user_id DESCdb.users.find( {status:"A" } ).sort( {user_id:-1 } )
Select COUNT(*) FROM usersdb.users.count() 或者 db.users.find().count()
Select COUNT(user_id) FROM usersdb.users.count( {user_id: {$exists:true } } ) 或者 db.users.find( {user_id: {$exists:true } } ).count()
Select COUNT(*) FROM users Where age>30db.users.count( {age: {$gt:30 } } ) 或者 db.users.find( {age: {$gt:30 } } ).count()
Select DISTINCT(status) FROM usersdb.users.distinct("status" )
Select * FROM users LIMIT 1db.users.findOne() 或者 db.users.find().limit(1)
Select * FROM users LIMIT 5 SKIP10db.users.find().limit(5).skip(10)
EXPLAIN Select * FROM users Where status="A"db.us


2.insert

SQL 命令MongoDB 命令
Insert INTO users(user_id,age,status) VALUES ("bcd001",45,"A")db.users.insert({user_id:"bcd001",age:45,status:"A"})


3.update

SQL命令MongoDB 命令
Update users SET status="C" Where age>25db.users.update({ age: { $gt:25 } },{ $set: { status:"C" } },{ multi:true } )
Update users SET age=age+3 Where status="A"db.users.update({ status:"A" } ,{ $inc: { age:3 } },{ multi:true })


4.delete

SQL 命令MongoDB 命令
Delete FROM users Where status="D" db.users.remove( { status:"D" } )
Delete FROM users db.users.remove({})


MongoDB
 
除非特别声明,本站所有PHP教程及其他教程/文章均为原创、翻译或网友投稿,版权均归UncleToo中文网所有, 转载请注明作者及出处。
原文网址:http://www.uncletoo.com/html/nosql/955.html
读完这篇文章后,你是否有所收获? 分享是一种生活的信念!
  • 0
  • 0
我来说两句
更多>>网友评论