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