日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

mongodb query

發布時間:2025/6/15 65 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mongodb query 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

query document 結構

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(標準) 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 在數組里
$nin 不在數組里

logical

$or
$and 逗號也表示$and
$not
$nor returns all documents that fail to match both clauses

Element

$exists 存在這個field
$type 類型匹配

Evaluation(計算)

$mod 模運算
$regex regular expression.
$text Performs text search.
$where satisfy a JavaScript expression.

Array

$all contain all elements specified in the query.
$elemMatch
$size 元素個數

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> } )

轉載于:https://www.cnblogs.com/jcuan/p/5698872.html

總結

以上是生活随笔為你收集整理的mongodb query的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。