0

我在 Atlas 中有一个 MongoDB,并且有一个已createAt/lastModifiedAt 字段的集合。我想设置触发器来自动处理这些字段。以下是我设置 createdAt 的触发器:

const collection = context.services.get("comand-dev").db("test").collection("ownerDetails");
const docId = changeEvent.documentKey._id;
collection;
collection.update(
  {_id : docId} ,
  { 
    $set : 
     {
       createdAt: Date()
     } 
  }
);

此触发器函数引发以下错误,我不知道我需要做什么才能成功触发:

TypeError: 'update' is not a function
> trace: 
TypeError: 'update' is not a function
    at exports (function.js:44:3)
    at apply (<native code>)
    at function_wrapper.js:2:3
    at <anonymous>:12:1

4

1 回答 1

0

根据文档,您应该使用updateOneor updateMany

于 2020-04-21T02:19:00.237 回答