日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

mongodb query

發(fā)布時(shí)間:2025/6/15 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mongodb query 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

query document 結(jié)構(gòu)

db.collection.find( <query filter>, <projection> )

a query filter: specify which documents to return.
a query projection : specifies which fields from the matching documents to return. The projection limits the amount of data that MongoDB returns to the client over the network.
You can optionally add a cursor modifier to impose limits, skips, and sort orders. The order of documents returned by a query is not defined unless you specify a sort().

Query on Embedded Documents

Exact Match

To specify an exact equality match on the whole embedded document, use the query document { : } where is the document to match. Equality matches on an embedded document require an exact match of the specified , including the field order.

Equality Match on Fields

db.users.find( { "favorites.artist": "Picasso" } )

Query on Arrays

When the field holds an array, you can query for an exact array match or for specific values in the array
If you specify multiple conditions without using the $elemMatch operator, then some combination of the array elements, not necessarily a single element, must satisfy all the conditions; i.e. different elements in the array can satisfy different parts of the conditions

exact match

Equality matches on the array require that the array field match exactly the specified , including the element order

db.users.find( { badges: [ "blue", "black" ] } )

Match an Array Element

Equality matches can specify a single element in the array to match. These specifications match if the array contains at least one element with the specified value

db.users.find( { badges: "black" } )

Match a Specific Element of an Array

badges is an array that contains "black" as the first element:

db.users.find( { "badges.0": "black" } )

Specify Multiple Criteria(標(biāo)準(zhǔn)) for Array Elements

Single Element Satisfies the Criteria

$elemMatch : at least one array element

db.users.find( { finished: { $elemMatch: { $gt: 15, $lt: 20 } } } )

Combination of Elements Satisfies the Criteria

e.g., one element can satisfy the greater than 15 condition and another element can satisfy the less than 20 condition, or a single element can satisfy both

db.users.find( { finished: { $gt: 15, $lt: 20 } } )

使用操作符

Comparison

小于等于$lte
大于 $gt
大于或等于$gte
不等于$ne
$in 在數(shù)組里
$nin 不在數(shù)組里

logical

$or
$and 逗號(hào)也表示$and
$not
$nor returns all documents that fail to match both clauses

Element

$exists 存在這個(gè)field
$type 類型匹配

Evaluation(計(jì)算)

$mod 模運(yùn)算
$regex regular expression.
$text Performs text search.
$where satisfy a JavaScript expression.

Array

$all contain all elements specified in the query.
$elemMatch
$size 元素個(gè)數(shù)

comments

$comment Adds a comment to a query predicate.
associates a comment to any expression taking a query predicate.
for example:

db.collection.find( { <query>, $comment: <comment> } )

轉(zhuǎn)載于:https://www.cnblogs.com/jcuan/p/5698872.html

總結(jié)

以上是生活随笔為你收集整理的mongodb query的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。