N
N
Nastya090922019-12-10 10:44:19
MongoDB
Nastya09092, 2019-12-10 10:44:19

How to rewrite mongo query without $facet?

const query = {
        $aggregate: [
            { $match: { active: { $ne: false } } },
            {
                $facet: {
                    buyers: [{ $match: { userType: 'media_buyer' } }, { $project: { _id: 1, fullName: 1 } }],
                    managers: [{ $match: { userType: 'account_manager' } }, { $project: { _id: 1, fullName: 1 } }],
                    campaignManagers: [
                        { $match: { userType: 'campaign_manager' } },
                        { $project: { _id: 1, fullName: 1 } },
                    ],
                },
            },
        ],
    };
    return User.get(query).then(r => r[0]);

Good afternoon, please tell me:
How can I rewrite such a request without using $facet.
Needed for compatibility with DocumentDB.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question