【发布时间】:2018-06-23 15:37:49
【问题描述】:
我在节点 js 服务器上的 mongoose 中使用 .find() 函数时遇到问题,我一直在尝试使用它,但无法从数据库中获取关键信息。
user.find({key: 1} , function(err, data){
if(err){
console.log(err);
};
console.log("should be the key VVV");
console.log(data.key);
});
我主要是无法理解这个函数如何接受查询并返回来自数据库的响应。如果有人可以将其分解,我将非常感谢 mongoose 文档并没有太大帮助。
如果有帮助,这也是我的用户架构
var userSchema = new mongoose.Schema({
username: {type: String, unique: true},
password: {type: String},
key: {type: String},
keySecret: {type: String}
}, {collection: 'user'});
var User = mongoose.model('user',userSchema);
module.exports = User;
【问题讨论】:
标签: javascript node.js mongoose