0

I have nested documents/schemas in my Mongoose, with a plan to use different schemas to separate concerns.

The data all looks correct in my DB, however, when trying to pull it out, I only get arrays of object Object.

Below is the console from docker-compose and a console.log on returning the user

timr-app    | [ { _id: 595be74705426a0001f68c7a,
timr-app    |     name: 'Stu Sklinar',
timr-app    |     __v: 0,
timr-app    |     events: [ [Object], [Object], [Object] ] }

User Schema:

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);

Event Schema:

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,
}
Stuart.Sklinar
  • 3,683
  • 4
  • 35
  • 89

1 Answers1

0

console.log doesn't print nested objects.

Instead you can do this:

const util = require('util');
console.log(util.inspect(myObject, false, null))
Abhyudit Jain
  • 3,640
  • 2
  • 24
  • 32