我使用TypeScript/Javascript与Meteor/Mongo。Mongo光标更新
我正在尝试更新其lastMessageCreatedAt
字段上带有时间戳的光标。
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.
},
模型
interface Chat {
_id?: string;
memberIds?: string[];
title?: string;
picture?: string;
lastMessage?: Message;
lastMessageCreatedAt?: Date;
receiverComp?: Tracker.Computation;
lastMessageComp?: Tracker.Computation;
}
问题
不过,我得到上述错误。我如何更新光标以获得时间戳?我是Meteor/Mongo的新手,所以我可能会接近完全错误的。
感谢您的回复。但是,这不会更新。我也没有看到任何错误。时间戳保持不变:'{ “_id”: “8wca85kB7tHEudgjJ”, “memberIds”:[ “P9”, “J64” ], “lastMessageCreatedAt”:“2016-09-16T16:13:35.942 Z“ } ]' – Richard
嗨,我已更正了代码。我错过了'全部'运营商。 – Ankit
谢谢。我测试了它,但它仍然没有更新:'[{“_id”:“8wca85kB7tHEudgjJ”,“memberIds”:[“P9”,“J64”],“lastMessageCreatedAt”:“2016-09-16T16:13:35.942 Z“}] app.bundle.js(line 481) updateChat:P9,J64,Fri Sep 16 2016 21:34:45 GMT + 0200(南非标准时间) app.bundle.js(line 483) [{“_id”:“8wca85kB7tHEudgjJ”,“memberIds”:[“P9”,“J64”],“lastMessageCreatedAt”:“2016-09-16T16:13:35.942Z”}]' – Richard