Nodebb如何使用mongodb api

时间:2017-12-20 08:06:09

标签: mongodb nodebb

我遇到了麻烦。有人想告诉我如何在Nodebb中写sql(mongondb + collections)。

var schoolnumber = req.session[cas.session_name];
    db.getObjectField('schoolnumber:' + schoolnumber, 'uid', function(err, ans) {
        console.log(1);
        if (err) {
            console.log('err');
        }else {
            console.log(ans)
            if (ans == null) {
                // res.redirect(nconf.get('relative_path') + '/register');
            }else {
                res.send( '<html><body>Hello!' + '</body></html>' );
            }
        }
    });

但我得到了这个

1
null

我想知道如何选择&#39; (如mysql)NodeBB(mongodb)中的数据通过字段(如&#39; schoolnumber&#39;)

1 个答案:

答案 0 :(得分:0)

不确定,但does this works for you

db.objects.find({_key:"users:postcount"}, {_id: 0}).sort({score: -1}).pretty()


{ "_key" : "users:postcount", "value" : "2", "score" : 4121 }
{ "_key" : "users:postcount", "value" : "970", "score" : 2749 }
{ "_key" : "users:postcount", "value" : "3", "score" : 2190 }
{ "_key" : "users:postcount", "value" : "1", "score" : 1707 }
{ "_key" : "users:postcount", "value" : "598", "score" : 769 }
{ "_key" : "users:postcount", "value" : "11", "score" : 733 }
{ "_key" : "users:postcount", "value" : "477", "score" : 546 }
{ "_key" : "users:postcount", "value" : "587", "score" : 504 }
{ "_key" : "users:postcount", "value" : "747", "score" : 467 }
{ "_key" : "users:postcount", "value" : "302", "score" : 449 }