提前感谢您对此的帮助,非常感谢!
我在一个新项目中使用 Node.js、MongoDB 和 Mongoose,我只是在尝试访问find()
数据库中的文档。为简洁起见,我将只包含下面的 Mongoose 代码(我现在并没有做更多的事情):
var mongoose = require('mongoose');
mongoose.connect('mongodb://<username>:<password>@<sub-domain>.mongolab.com:<port>/<db>');
var schema = { email_address: String, invite: String }
, Users = mongoose.model('Users', new mongoose.Schema(schema));
console.log(Users.findOne({ 'email_address': 'jonathon@foo.bar' }, function(err, doc) { return doc; }));
我很确定应该只是将返回的内容回显doc
到 Node.js 控制台(终端),但我得到的是:
{ options: { populate: {} },
safe: undefined,
_conditions: { email_address: 'jonathon@foo.bar' },
_updateArg: {},
_fields: undefined,
op: 'findOne',
model:
{ [Function: model]
modelName: 'Users',
model: [Function: model],
options: undefined,
db:
{ base: [Object],
collections: [Object],
models: {},
replica: false,
hosts: null,
host: '<sub-domain>.mongolab.com',
port: <port>,
user: '<username>',
pass: '<password>',
name: '<db>',
options: [Object],
_readyState: 2,
_closeCalled: false,
_hasOpened: false,
db: [Object] },
schema:
{ paths: [Object],
subpaths: {},
virtuals: [Object],
nested: {},
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
statics: {},
tree: [Object],
_requiredpaths: undefined,
options: [Object] },
collection:
{ collection: null,
name: 'users',
conn: [Object],
buffer: true,
queue: [Object],
opts: {} },
base:
{ connections: [Object],
plugins: [],
models: [Object],
modelSchemas: [Object],
options: {},
Collection: [Function: NativeCollection],
Connection: [Function: NativeConnection],
version: '3.5.4',
Mongoose: [Function: Mongoose],
Schema: [Object],
SchemaType: [Object],
SchemaTypes: [Object],
VirtualType: [Function: VirtualType],
Types: [Object],
Query: [Object],
Promise: [Function: Promise],
Model: [Object],
Document: [Object],
Error: [Object],
mongo: [Object] } } }
显然,我只是用这些<username>
位混淆了我的真实凭证,它们在我的代码中都是正确的。
数据库中确实有一个与条件匹配的文档,即使从findOne
方法中删除条件也不会产生任何结果!
我对 Node.js 相当陌生,所以我可以解释你的答案,所以我知道下次它会很有帮助!谢谢!