Я использую стежок в mongodb. В стежке я пишу одну nodejs функцию для увеличения и уменьшения.
if(changeEvent.fullDocument.type == 'article' || changeEvent.fullDocument.type == 'poll' ) {
context.functions.execute("notifyTopic", "article-created", changeEvent.fullDocument);
var communities = context.services.get("mongodb-atlas").db("utilo").collection("communities");
communities.updateOne(
{_id:changeEvent.fullDocument.community},
{$inc: {"summary.postCount":NumberInt(1)}, $currentDate: {"summary.lastActivity":true} }
)
} else if (changeEvent.fullDocument.type == 'comment') {
context.functions.execute("notifyTopic", "comment-created", changeEvent.fullDocument);
var posts = context.services.get("mongodb-atlas").db("utilo").collection("posts");
posts.updateOne(
{_id:changeEvent.fullDocument.root},
{$inc: {"summary.commentCount":1}, $currentDate: {"summary.lastActivity":true} }
)
Теперь я выполнил эту функцию, значение summary.postCount, преобразованное из int в Double, я использую NumberInt также .
posts.updateOne(
{_id:changeEvent.fullDocument.root},
{$inc: {"summary.commentCount":NumberInt(1)}, $currentDate: {"summary.lastActivity":true} }
)
communities.updateOne(
{_id:changeEvent.fullDocument.community},
{$inc: {"summary.postCount":NumberInt(-1)}, $currentDate: {"summary.lastActivity":true} }
)
это не рабочее событие, я также упомянул "summary. $. PostCount", но это бесполезно.
Мне нужны только значения увеличения / уменьшения и целочисленный тип данных. Пожалуйста, помогите мне с решением. Заранее спасибо.