小編給大家分享一下mongodb查詢語句的案例,相信大部分人都還不怎么了解,因此分享這邊文章給大家學習,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去學習方法吧!
如果覺得 Mongodb 語句不太好理解,可以和 SQL 語句進行對比,學起來要容易很多。
查詢(find)
查詢所有結果
select * from article db.article.find()
指定返回哪些鍵
select title, author from article db.article.find({}, {"title": 1, "author": 1})
where條件
select * from article where title = "mongodb" db.article.find({"title": "mongodb"})
and條件
select * from article where title = "mongodb" and author = "god" db.article.find({"title": "mongodb", "author": "god"})
or條件
select * from article where title = "mongodb" or author = "god" db.article.find({"$or": [{"title": "mongodb"}, {"author": "god"}]})
比較條件
select * from article where read >= 100; db.article.find({"read": {"$gt": 100}}) > $gt(>)、$gte(>=)、$lt(<)、$lte(<=) select * from article where read >= 100 and read <= 200 db.article.find({"read": {"$gte": 100, "lte": 200}})
in條件
select * from article where author in ("a", "b", "c") db.article.find({"author": {"$in": ["a", "b", "c"]}})
like
select * from article where title like "%mongodb%" db.article.find({"title": /mongodb/})
count
select count(*) from article db.article.count()
不等于
select * from article where author != "a" db.article.find({ "author": { "$ne": "a" }})
以上是mongodb查詢語句的案例的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。