Reputation: 1
Hello I have small problem with my call to mongoDB. Im using $set functionality on my localhost, and it works super fine, yet after using it on production enviroment we getting error because mongoDB version is 4.0, we cannot upgrade Database so my question, is there ANY replacement for $Set in version 4.0? can I use anything to achive same call?
Call to mongo:
const templateList = await this.templatesModel.aggregate([
{
$facet: {
data: [
{
$lookup:
{
from: 'extensions',
localField: 'extensionName',
foreignField: 'extension',
as: 'extension',
},
},
{ $unwind: '$extension' },
{ $set: { bundleIds: '$extension.bundle' } },
{ $match: filter },
{ $skip: offset },
{ $limit: limit },
{
$project: {
extensionName: 1,
isDefault: 1,
previewImage: 1,
published: 1,
title: 1,
updated: 1,
},
},
],
totalCount: [
{
$lookup:
{
from: 'extensions',
localField: 'extensionName',
foreignField: 'extension',
as: 'extension',
},
},
{ $unwind: '$extension' },
{ $set: { bundleIds: '$extension.bundle' } },
{ $match: filter },
{ $count: 'count' },
],
},
},
]).exec();
Upvotes: 0
Views: 150
Reputation: 3349
You can replace $set
with $addFields
.
Both these stages perform the same task since $set is nothing but an alias of $addFields.
Upvotes: 2