admin管理员组文章数量:1291062
I have a mongoose schema as follows
var user_schema = new Schema({
reset : { type: Schema.Types.Mixed, required: true }
});
where reset is being given an object like this to store in the database
{
id: 23,
name: 'something'
}
I would like to look up a document based on the id in the reset object. This is what I have tried but I never get a result returned.
models.Users.findOne({ 'reset.id': id }, function (err, user) {
// user is null
});
Is a lookup like this possible with mongoose?
I have a mongoose schema as follows
var user_schema = new Schema({
reset : { type: Schema.Types.Mixed, required: true }
});
where reset is being given an object like this to store in the database
{
id: 23,
name: 'something'
}
I would like to look up a document based on the id in the reset object. This is what I have tried but I never get a result returned.
models.Users.findOne({ 'reset.id': id }, function (err, user) {
// user is null
});
Is a lookup like this possible with mongoose?
Share Improve this question asked Nov 13, 2012 at 15:54 Errol FitzgeraldErrol Fitzgerald 3,0082 gold badges28 silver badges35 bronze badges1 Answer
Reset to default 9I think the issue you're having is with using mixed schema type.
Could you not use an embedded doc of Reset
var reset_schema = new Schema({
id : Int,
name : String
});
var user_schema = new Schema({
name : String,
reset : reset_schema
});
And then querying like:
models.Users.findOne({ 'reset.id': id }, function (err, user) {
});
本文标签: javascriptMongoose findOne on object propertyStack Overflow
版权声明:本文标题:javascript - Mongoose findOne on object property - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741518176a2383021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论