【发布时间】:2020-04-21 10:19:00
【问题描述】:
我在 Atlas 中有一个 MongoDB 和一个包含 createdAt/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
【问题讨论】:
标签: mongodb mongodb-atlas