From c3a98d8a2008f1dbf885290629b1090a65555905 Mon Sep 17 00:00:00 2001 From: Dono <3781087+Donorhan@users.noreply.github.com> Date: Mon, 14 Aug 2023 11:28:16 +0200 Subject: [PATCH] 1 - messages: fix error with insertMany --- core/modules/messages/server/messages.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/modules/messages/server/messages.js b/core/modules/messages/server/messages.js index 3bb83639a..fe908b9ab 100644 --- a/core/modules/messages/server/messages.js +++ b/core/modules/messages/server/messages.js @@ -60,14 +60,16 @@ const notifyUsers = message => { userIds = Meteor.users.find({ _id: { $ne: createdBy }, 'status.online': true, 'profile.levelId': channel }, { fields: { 'profile._id': 1 } }).fetch().map(item => item._id); } else userIds = channel.split(';').filter(userId => userId !== createdBy); - const notifications = userIds.map(userId => ({ - _id: Notifications.id(), - channelId: channel, - userId, - createdAt: new Date(), - createdBy, - })); - Notifications.rawCollection().insertMany(notifications); + if (userIds.length) { + const notifications = userIds.map(userId => ({ + _id: Notifications.id(), + channelId: channel, + userId, + createdAt: new Date(), + createdBy, + })); + Promise.await(Notifications.rawCollection().insertMany(notifications)); + } log('notifyUsers: done', { userIds }); };