[英]Mongoose retrieve an specific array index from a query (not the full array)
[英]able to query specific index in array? mongoose
例如,如果我有以下documents
{
"field": [
"hello",
"random wording",
{
"otherId": 3232,
"otherId2": 32332
}
],
}
是否可以說有一個與index 0
和index 2
匹配的查詢
我嘗試使用諸如model.find({field: "hello")
查詢來查詢它。
但是,如果我想混合和匹配,那么我想進行一個與index 0
和index 2
匹配的查詢,或者說在index 2
該值實際上是一個我想用"otherId2": 32332
進行查詢的object
"otherId2": 32332
,相反,我需要匹配整個object
在此先感謝您的幫助或建議。
查詢恰好在數組索引0處的值
model.find({'field.0': 'hello'})
引用數組索引僅適用於第一級數組。
通過對象的屬性查詢出現在數組的索引2
model.find({'field.2.otherId': 3232})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.