These are chat archives for Automattic/mongoose

30th
Oct 2018
Kev
@lineus
Oct 30 2018 10:09
@mbellemo_twitter The $and in your filter is superfluous because it only has one condition gist here.
Another approach would be to create a text index on the fields associated with your req.query.search and use text search to look for the values in both fields with one $text property on your filter gist here. There are plenty of caveats with text indexes though. So be sure to check out the docs before changing anything.
Slim Hmidi
@slim-hmidi
Oct 30 2018 15:29
Hi, is it possible to combine aggregate with populate in mongoose??

I wrote this query:

const filteredTasks = await Tasks.aggregate([])
        .match({ statusId: native.Types.ObjectId(statusId) })
        .project({
          name: 1,
          typeId: 1,
          statusId: 1,
          position: { $arrayElemAt: [{ $map: {
            input: {
              $filter: {
                input: '$attributes',
                as: 'attribute',
                cond: { $eq: ['$$attribute.attributeId', native.Types.ObjectId('5bd858e29ae710297c649688')] },
              },
            },
            as: 'attributeType',
            in: '$$attributeType.value',

          } }, 0] },
        });

The collection Tasks has join with two other collections through typeId and statusId and I want to populate the query with the referenced collections.How can I do that?