I'm currently working on a query that needs to meet two criteria: matching a specific userID and also matching a range of IDs.
Here's an example of what a document might look like: https://i.sstatic.net/sIF3K.png
My approach involved using the find
function to specify the userID
, followed by utilizing MongoDB's $in
operator to match a list of feature
IDs.
const featureIds = features.map(feature => feature._id)
console.log(featureIds)
const isFeatureExists = await this.userShopModel.find({
userId,
'items.feature': { $in: featureIds },
})
console.log(isFeatureExists)
I've also experimented with different versions of the aggregate
method, but unfortunately haven't had any success yet.
If there are any MongoDB experts out there who could lend me a hand, I would greatly appreciate it!