Hi there,
I have two collections:
- Users
- Orders
The orders have a key user data type ObjectId referencing a user.
I would like to do an aggregate search through the orders AND the users within.
Something like this ( doesn’t work ):
const { search } = req.params
let orders = await Orders.aggregate([
{
'$search': {
'index': 'ranges',
'text': {
'query': search,
'path': {
'wildcard': '*'
}
}
}
}
])
orders = await Orders.populate(orders, { path: "user productsBought.range" })
But like this I am populating after finding, which is not finding orders by user name.
Any help is appreciated.
Thanks!