admin管理员组文章数量:1386692
For example if I have below as my documents
{
"field": [
"hello",
"random wording",
{
"otherId": 3232,
"otherId2": 32332
}
],
}
is it possible to let's say have a query that matches the index 0
and index 2
I tried having query such as
model.find({field: "hello")
which seem to work to query it.
But if I want to mix and match, let's say I want to make a query that matches whatever index 0
and index 2
or let's say in index 2
the value is actually an object
that I want to query all with "otherId2": 32332
, instead that I need to match the whole object
Thanks in advance for any help or advises.
For example if I have below as my documents
{
"field": [
"hello",
"random wording",
{
"otherId": 3232,
"otherId2": 32332
}
],
}
is it possible to let's say have a query that matches the index 0
and index 2
I tried having query such as
model.find({field: "hello")
which seem to work to query it.
But if I want to mix and match, let's say I want to make a query that matches whatever index 0
and index 2
or let's say in index 2
the value is actually an object
that I want to query all with "otherId2": 32332
, instead that I need to match the whole object
Thanks in advance for any help or advises.
Share Improve this question asked Jul 26, 2018 at 18:15 DoraDora 7,01015 gold badges58 silver badges116 bronze badges 01 Answer
Reset to default 7Query for a value exactly at an index 0 of array
model.find({'field.0': 'hello'})
Referencing array indexes works for the first-level array only.
Query by object property present at index 2 of array
model.find({'field.2.otherId': 3232})
本文标签: javascriptable to query specific index in array mongooseStack Overflow
版权声明:本文标题:javascript - able to query specific index in array? mongoose - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744554689a2612400.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论