admin管理员组文章数量:1420966
I have a mongoose Schema that looks like this:
var mySchema = new mongoose.Schema({
...
metadata: {
isDeleted: {
type: Boolean,
default: false
},
...
}
});
I want to get the list of elements in my mongodb database applying a filter, so I have the following object:
var searchOptions = { metadata: { isDeleted: false } };
that always needs to have that metadata.isDeleted
value set to false
, appart from other parameters that will be added later, before executing the query:
var objQuery = myModel.find(searchOptions, '-metadata');
At first, I had isDeleted
attribute outside my metadata
object in the Schema, and
var searchOptions = { isDeleted: false };
used to work perfectly. But it is since I decided to have isDeleted
inside my metadata
object that is not working and can't figure out why...
I have a mongoose Schema that looks like this:
var mySchema = new mongoose.Schema({
...
metadata: {
isDeleted: {
type: Boolean,
default: false
},
...
}
});
I want to get the list of elements in my mongodb database applying a filter, so I have the following object:
var searchOptions = { metadata: { isDeleted: false } };
that always needs to have that metadata.isDeleted
value set to false
, appart from other parameters that will be added later, before executing the query:
var objQuery = myModel.find(searchOptions, '-metadata');
At first, I had isDeleted
attribute outside my metadata
object in the Schema, and
var searchOptions = { isDeleted: false };
used to work perfectly. But it is since I decided to have isDeleted
inside my metadata
object that is not working and can't figure out why...
1 Answer
Reset to default 7It seems pretty likely given your use of elipsis in your schema listing that there are more properties than isDeleted
under the metadata
property. So your object should be:
var searchOptions = { "metadata.isDeleted": false } };
The reason for this is that otherwise the query is looking for a document with "exactly" and "only" the properties named under the metadata
key:
var searchOptions = { metadata: { isDeleted: false } };
And when that is not the case, then of course there is no match.
本文标签: javascriptMongoosefind() object inside search options is not workingStack Overflow
版权声明:本文标题:javascript - Mongoose - find(): object inside search options is not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745319496a2653310.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论