溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

mongodb查詢語句的案例

發(fā)布時間:2020-07-30 10:17:25 來源:億速云 閱讀:147 作者:清晨 欄目:編程語言

小編給大家分享一下mongodb查詢語句的案例,相信大部分人都還不怎么了解,因此分享這邊文章給大家學(xué)習(xí),希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去學(xué)習(xí)方法吧!

如果覺得 Mongodb 語句不太好理解,可以和 SQL 語句進(jìn)行對比,學(xué)起來要容易很多。

查詢(find)

查詢所有結(jié)果

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查詢語句的案例的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI