These are chat archives for Automattic/mongoose

8th
Aug 2017
Tyler Finethy
@tylfin
Aug 08 2017 14:59
Hey guys, I'm running into a MongoError: connection 33 to XX:27017 timed out error. I have retries & keepAlive set. The problem is the initial find is failing, is there anyway to get the find to hang until the connection has reconnected?
The mongoError is causing havoc all over the place, even while the DB successfully reconnects
Ayush Bahuguna
@relentless-coder
Aug 08 2017 16:02
User.update({ 'chats.$.room': message.room }, { $set: { 'lastMessage':  { message: message.message, date: message.date }}}, {multi: true})
                        .then((done) => {
                          socket.to(message.room).emit('messageReceived', msg)

                        })
What I am trying to do is update the 'lastMessage' path which is inside and array of objects. But this isn't working, nor am I getting any error
chats: [{room: String, partner: String, lastMessage: {message: String, date: String}}]
This is the path inside a User schema
Alexander
@Faltek
Aug 08 2017 20:00

Hello everyone! I have a question about saving new Item to my collection which has a reference:

var schema = new Schema({
    _id: Schema.Types.ObjectId,
    teacher: { type: Schema.Types.ObjectId, ref: 'User' },
    student: { type: Schema.Types.ObjectId, ref: 'User' },
    type: Number,
    history: [historySchema]
}, { collection: 'connections' });

So I want to add an Item like this:

const connection = new Connection({
        _id: new mongoose.Types.ObjectId(),
         teacherId: new ObjectId(teacherId),
         studentId: new ObjectId(studentId),
         type: 0
     });
    return connection.save().then(res => {
        return mapConnection(res);
    });
But it doesn't save Teacher and Student id's
what am I doing wrong?