我试图在我的 nodeJs 应用程序中运行这个查询
Book.find({'user._id': '545e2915cd91299447fdb8d7'}).populate('user').exec(function(err, books){...}
它不工作(它返回空列表)但我尝试使用 mongo 在 cmd 中运行此查询并且它正在工作。谁能帮帮我吗?
这是书的计划:
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
path = require('path');
/**
* Book Schema
*/
var BookSchema = new Schema({
title: {
type: String,
trim: true,
required: 'Title is missing'
},
created: {
type: Date,
default: Date.now
},
user: {
type: Schema.ObjectId,
ref: 'User'
}
});
mongoose.model('Book', BookSchema);