Mongo Cursor update


#1

Hi All,

I am trying to update a cursor with a timestamp on its lastMessageCreatedAt field.

  updateChat(senderId: string, chatId: string): void {

    const chatExists = !!Chats.find(chatId).count();
    if (!chatExists) throw new Meteor.Error('chat-not-exists',
      'Chat doesn\'t exist');

    const chat1 = Chats.find(chatId);
    const receiverId = chat1.memberIds.find(memberId => memberId != senderId);  // <=== error TS2339: Property 'memberIds' does not exist on type 'Cursor<Chat>'.

    const chat = {
      memberIds: [senderId, receiverId],
      lastMessageCreatedAt: new Date()
    };

    Chats.update(chat);   // <=== error TS2346: Supplied parameters do not match any signature of call target.
  },

model

  interface Chat {
    _id?: string;
    memberIds?: string[];
    title?: string;
    picture?: string;
    lastMessage?: Message;
    lastMessageCreatedAt?: Date;
    receiverComp?: Tracker.Computation;
    lastMessageComp?: Tracker.Computation;
  }

Question

However, I get the above errors. How do I update the cursor to have the timestamp? I am new to Meteor/Mongo, so I may be approaching this entirely wrong.

Thank you.


#2

Solution

Chats.update({ _id: chatId}, { $set: { lastMessageCreatedAt: date } });