-
Originally asked: https://stackoverflow.com/questions/74236990/how-to-filter-query-on-a-view-of-a-collection-in-mongoose I have a model that's a view of another collection that I create like such: NewSchema.createCollection({
viewOn: originalModel.collection.collectionName,
pipeline: [
{
'$project': {
uuid: 1,
name: 1,
description: 1,
image_url: 1,
price: 1,
avg_rating: 1
}
},
],
}); But when we do queries on the new schema, like this: const res = await NewSchema.find({name: {$regex: keywords, $options: 'i' }}).sort({ 'price': -1 });
// or
const res = await NewSchema.find({uuid: "Something Random"}); The results contain everything in the original collection (the projection works, but the filter does not). When we do the query on the base collection, the filter works. Is it possible to filter a query with mongoose on a model that's a view of another schema? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Try |
Beta Was this translation helpful? Give feedback.
Try
mongoose.set('strictQuery', false)
?