Я хочу вернуть все разговоры в чате, участником которых является вошедший в систему пользователь (user_id).
Я хочу заполнить участников, возвращая только имя profile.firstname (может быть, какое-то другое позже), затем я хочу отфильтровать участников, чтобы он не возвращал loggedInUser (user_id) в массиве участников.
ИНДЕКС chat.controller.js
Chat.find({participants: user_id})
.populate('participants', {
select: 'profile.firstname',
where('_id').ne(user_id) // This need to change
})
.exec(function (err, chats) { });
чат.model.js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
let ChatSchema = new Schema({
participants: [{
type: Schema.Types.ObjectId, ref: 'User'
}],
messages: [{
type: Schema.Types.ObjectId, ref: 'Message'
}],
},
{
timestamps: {createdAt: 'created_at', updatedAt: 'updated_at'}
});
module.exports = mongoose.model('Chat', ChatSchema);