Issue
I'm currently using mongoose, and create a view on a collection.
NewSchema.createCollection({
viewOn: originalModel.collection.collectionName,
pipeline: [
{
$project: keep.reduce((a, v) => ({ ...a, [v]: 1 }), {}),
},
],
});
This creates a new schema and only shows the fields that are passed in as keep
.
This creates a model with this kind of 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 })
But the results always contain everything in the collectin. 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?
Solution
You have to do mongoose.set('strictQuery', false)
somewhere before all your models and schemas are created. Answered by Valeri Karpov the creator of mongoose on GitHub discussions.
Answered By - joshpetit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.