I have complex object stored in my mongodb look like this:
const collectionFromMongodb = [
{
id: ObjectID(),
text: 'blabla',
data: {
foo: [
{ id: ObjectID(), status: 'ready' },
{ id: ObjectID(), status: 'notready' },
],
bar: [
{ id: ObjectID(), status: 'ready' },
{ id: ObjectID(), status: 'notready' },
],
},
},
];
I want to query the all the object (find) but the object that return will have in foo and bar only object that status are ready. (data.foo.[?].status === 'ready' and/or data.bar.[?].status === 'ready').
I expect to get all the object (since my filter is only on data), but the fields of foo and bar contains only the status of 'ready'.
Note: In foo and bar I have data size of 1mb.
How to do that with mongoose query? is it possible to do? or just query all object and use filter and map?
I did this but not works, because its gets all the statuses in data.foo:
find('data.foo': { $elemMatch: { status: 'ready' })
tableis not an object, it looks like an array of objects.and/oris not possible. Is has to be either one of them? You need to satisfy both condition or either one of them?fooandbar(if any) only those with status ofready.