If I had a field in every document of a collection called array_field, which consists of elements of type object, could I query for a specific field in the objects?
- collection
- document1
- array_field
0: { type: tree, age: 143 }
1: { type: sunflower, age: 1 }
2: { type: fungus, age: 3 }
- document2
- array_field
0: { type: plane, age: 38 }
1: { type: plant, age: 2 }
2: { type: fungus, age: 1 }
Is there a possibility to query for every document that has an object in its array_field with type fungus?
If that is not possible, is there a way to query for documents by specifying an exact object?
I do not know how I would go about writing the query: .where('array_field', 'array_contains', /*how do I define this object*/). Would it just be a JSON object like this: {type: fungus, age: 2}?
The query I am aiming to achieve is the following:
where('array_field', 'array_contains', 'type:fungus')
Which would return document1 and document2, but I could not find any hints on syntax for a case like this.