type const addToNotifications = await db.collection("notifications").findOneAndUpdate(
{ author: body.author },
{
$addToSet: {
notifications: {
comment: body.comment,
notifier: body.commenter,
postId: body.postId,
notificationType: "comment",
isSeen: false,
createdAt: new Date(),
},
},
},
{ returnDocument: "after" }
);
const removeFromNotifications = await db.collection("notifications").findOneAndUpdate(
{ author: body.author },
{
$pull: {
notifications: {
isSeen: true,
createdAt: { $lt: new Date(Date.now() - 1 * 60 * 1000) }, // Older than 1 day
},
},
},
{ returnDocument: "after" }
); or paste code here
``` here is my code
Skip to main content
New & Unread Topics
Topic | Replies | Views | Activity |
---|---|---|---|
isActive boolean that only allows one active item | 1 | 672 | Apr 2024 |
Parallelizing mongodump to dump large amount of data from multiple collections | 0 | 304 | Aug 2024 |
Exporting and loading data in multiple environments | 0 | 23 | Sep 2024 |
Time series queries performance is poor | 1 | 89 | Nov 2024 |
Upgrade from Mongo 6 to 8 and hint becoming really slow | 0 | 313 | Dec 2024 |