[英]How to set/modify value of a collection field from MongoDB Atlas triggers?
I have a MongoDB in Atlas and a collection that has createdAt/lastModifiedAt fields.我在 Atlas 中有一个 MongoDB 和一个已createAt/lastModifiedAt 字段的集合。 I would like to set up triggers to automatically handle these fields.我想设置触发器来自动处理这些字段。 The following is my trigger for setting createdAt:以下是我设置 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()
}
}
);
This trigger function throws the following error and I don't know what I need to do to have a successfull trigger:此触发器 function 引发以下错误,我不知道我需要做什么才能成功触发:
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
According to documentation you should be using updateOne
or updateMany
.根据文档,您应该使用updateOne
或updateMany
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.