【$in 操作符】
The $in operator selects the documents where the value of a field equals any value in the specified array.
$in 选择包含指定值之一的 doc。
If the field holds an array, then the $in operator selects the documents whose field holds an array that contains at least one element that matches a value in the specified array
Use the $in Operator with a Regular Expression
The $in operator can specify matching values using regular expressions of the form /pattern/. Youcannot use $regex operator expressions inside an $in.
Consider the following example:
db.inventory.find( { tags: { $in: [ /^be/, /^st/ ] } } )
This query selects all documents in the inventory collection where the tags field holds an array that contains at least one element that starts with either be or st.
参考:https://docs.mongodb.org/manual/reference/operator/query/in/#op._S_in
时间: 2024-10-23 15:58:39