Mongo(ose)返回对象数组对象
问题描述:
我在我的Mongoose中嵌套了文档/模式,计划使用不同的模式来分隔关注点。Mongo(ose)返回对象数组对象
数据在我的数据库中看起来都是正确的,但是,在试图将其拉出时,我只能获取Object对象的数组。
下面是从搬运工-撰写控制台和上返回用户的console.log
timr-app | [ { _id: 595be74705426a0001f68c7a,
timr-app | name: 'Stu Sklinar',
timr-app | __v: 0,
timr-app | events: [ [Object], [Object], [Object] ] }
用户架构:
var mongoose = require('mongoose');
var EventSchema = require('./event').schema;
// define the schema for our user model
var userSchema = mongoose.Schema({
facebookUserId: String,
token: String,
name: String,
events: [EventSchema]
});
// create the model for users and expose it to our app
module.exports = mongoose.model('User', userSchema);
事件架构:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var CourseSchema = require('./course.js').schema;
var EventSchema = new Schema({
course: CourseSchema,
date: Date,
time: String
}, {
bufferCommands: false,
timestamps: true
});
module.exports = {
EventSchema,
}
答
console.log
没有按不打印嵌套对象。
相反,你可以这样做:
const util = require('util');
console.log(util.inspect(myObject, false, null))
使用'console.dir(myObject的,{深度:3,颜色:真});' – nmanikiran