Javascript MongoDB Stitch-当数据类型随更新递减时,如何将其保持为int?

Javascript MongoDB Stitch-当数据类型随更新递减时,如何将其保持为int?,javascript,node.js,mongodb-stitch,Javascript,Node.js,Mongodb Stitch,我正在使用mongodb stitch函数,我有两个集合,如社区和帖子。当我在post collection中插入新文档时,我们需要在communities集合中增加+1 summary.postCount。当我在post collection中将状态更新为deleted时,我们需要在communities集合中减少-1 summary.postCount。我这样写函数 if(changeEvent.operationType == 'insert') { context.functions.e

我正在使用mongodb stitch函数,我有两个集合,如社区和帖子。当我在post collection中插入新文档时,我们需要在communities集合中增加+1 summary.postCount。当我在post collection中将状态更新为deleted时,我们需要在communities集合中减少-1 summary.postCount。我这样写函数

if(changeEvent.operationType == 'insert') {
context.functions.execute('addEventBySystem', 
  {
    community: changeEvent.fullDocument.community,
    channel: changeEvent.fullDocument.channel,
    origin: changeEvent.fullDocument.lastUpdatedBy,
    target: "",
    type: 'created',
    status: 'completed'
  });
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":1}, $currentDate: {"summary.lastActivity":true} }
  )
} else if(changeEvent.operationType == 'update') {
if(changeEvent.fullDocument.status == "deleted" && changeEvent.fullDocument.type == 'article' || 
changeEvent.fullDocument.type == 'poll') {
  var communities = context.services.get("mongodb-atlas").db("utilo").collection("communities");
  communities.updateOne(
    {_id:changeEvent.fullDocument.community},
    {$inc: {"summary.postCount":-1}, $currentDate: {"summary.lastActivity":true} }
  )
}
现在,在递减时,summary.postCount数据类型从int32更改为double。我也试着编号,但没用。如何仅在递增/递减后保持数据类型int


注意:在类似以下摘要的社区摘要字段中:{postCount:1,lastActivity:date}

这里肯定存在某种错误。我可以通过做
{$inc:{“x”:Number(1)}
来绕过它。这仍然会将其更改为int64,但至少比双精度更接近