Hello, there is such a scheme:
title: String, messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }], private: { type: Boolean, default: false }, users: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }] In the module I want to get a list of users for the room. In the stream, I delete from the array of users in the room (users) the id of the user who entered. And through populate I try to find another user in the room.
async.waterfall([ function(done){ var arr = []; var stream = Room.find({'$or': [{users: mongoose.Types.ObjectId(userId)}, {"private": false}]}).populate('users').lean().stream(); stream.on('data', function(room){ delete room.messages; room.users.length ? room.users.splice(room.users.indexOf(userId), 1) : null; arr.push(room); return arr }); stream.on('error', function(err){ }); stream.on('close', function(room){ done(null, arr) }); } ], function(err,data){ console.log(data) done(null,data) }); console.log (data) returns a list of rooms, where in each
users: [ [Object] ] But when accessing the user object console.log (data.users) I get undefined