-
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})
- db.users.find({"age" : {"$gte" : 18, "$lte" : 30}}) select * from users where age >=18 and age <= 30
- 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
- db.users.find({"name" : /joey?/i})
- db.food.find({fruit : {$all : ["apple", "banana"]}})
- db.food.find({"fruit.2" : "peach"})
- db.food.find({"fruit" : {"$size" : 3}})
- db.users.findOne(criteria, {"comments" : {"$slice" : 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"})
- db.foo.find({"$where" : "function() { return this.x + this.y == 10; }"})
- db.foo.find().sort({"x" : 1}).limit(1).skip(10);
-
相关阅读:
在windows下安装mongodb(1)
kettle过滤记录运用
Robberies(简单的01背包 HDU2955)
Alice and Bob(贪心HDU 4268)
A Simple Problem with Integers(树状数组HDU4267)
A Round Peg in a Ground Hole(凸包应用POJ 1584)
Fishnet(暴力POJ 1408)
Wall(凸包POJ 1113)
Pipe(点积叉积的应用POJ1039)
I love sneakers!(分组背包HDU3033)
-
原文地址:https://www.cnblogs.com/jinxf/p/9150345.html
Copyright © 2020-2023
润新知