我有以下文件
var UserSchema = new Schema({
name: String,
email: { type: String, lowercase: true },
offers: [],
anyCountry: {type: Boolean, default: false},
city: String,
});
var TagSchema = new Schema({
text: String,
dateCreated: { type: Date, default: Date.now}
});
我正在这样聚合:
User.aggregate(
{$match: {
$or: [
{'isBlocked': false},
{'isBlocked': {$exists: false}}
]}},
{ $project: {"offers": 1, _id: 0, city: 1, name: 1}},
{ $unwind: "$offers" },
{
$match: {
$and: [
{'offers': { $not: { $size: 0} }},
{'offers.type': type}
]
}
},
{ $sort: {"offers.dateCreated": -1} },
function (err, result) {
if (!err) {
return res.json({status: 'success', data: result});
} else {
return res.send(err);
}
}
)
输出正常,但它包含标签作为数组。我需要的是:
将数组值分配给计算字段" offers.tagsList"作为昏迷分开的刺痛{offers.tagsList = 'tag1, tag2, tag3, ...'}
。
检查归档offers.anyCountry
是否不存在,并将其添加到值为false
的输出中。
谢谢!