javascript – 如何在Mongoose中执行查询?

前端之家收集整理的这篇文章主要介绍了javascript – 如何在Mongoose中执行查询?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
> db.users.findOne();
{
    "_id" : ObjectId("4db8ebb4c693ec0363000001"),"fb" : {
        "name" : {
            "last" : "Sss","first" : "Fss","full" : "Fss"
        },"updatedTime" : "2011-04-27T09:51:01+0000","verified" : true,"locale" : "en_US","timezone" : "-7","email" : "abc@gmail.com","gender" : "male","alias" : "abc","id" : "17447214"
    }
}

那就是我的Mongo对象.现在我想通过Mongoose找到它:

User.findOne( { gender: "male" },function(err,docs){
    console.log(err);  //returns Null
    console.log(docs);  //returns Null.
});

那不行!这也不是:

User.findOne( { fb: {gender:"male"} },function...

空,null.

这是我的整个事情:

app.get('/:uid',function(req,res){
    params = {}
    User.findOne({ $where : "this.fb.gender == 'male' " },docs){
        console.log(docs);
    });
    res.render('user',{ locals:params });
});

解决方法

尝试这个 :
User.findOne( { $where : "this.fb.gender == 'male' " } )

要么

User.findOne( { fb.gender : "male" } )
原文链接:https://www.f2er.com/js/153638.html

猜你在找的JavaScript相关文章