[英]Save instances from Mongodb collection as string variables in an Atlas Trigger Function
I am trying to set up a MongoDB Atlas trigger function that searches a mongoDB database to collect string variables, then uses those as the to log into a separate API.我正在尝试设置一个 MongoDB Atlas 触发器函数,该函数搜索 mongoDB 数据库以收集字符串变量,然后将这些变量用作登录到单独的 API。 When I run this function:
当我运行这个函数时:
exports = function() {
const mongodb = context.services.get("mongodb-atlas");
const EventData = mongodb.db("SIoT").collection("EventData");
var data = EventData.find({"_id":new BSON.ObjectId("XXXXXXXX")})
return data
};
It returns:它返回:
EJSON.parse('[{"_id":{"$oid":"XXXXXXXXX"},"CodeRequestAuthorization":"XXXXXXXXXXX","DataRequestAuthorization":"XXXXXXXXXX"}]')
But I am trying to save the CodeRequestAuthorization value as a variable in the function.但我试图将 CodeRequestAuthorization 值保存为函数中的变量。
Feels like an incredibly simple problem but I have been stuck for about 5 hours.感觉这是一个非常简单的问题,但我已经被困了大约 5 个小时。
Managed to solve the problem myself:设法自己解决了这个问题:
exports = async function(){
const EventData = context.services.get("mongodb-atlas").db("SIoT").collection("EventData");
const request = await EventData.findOne({"_id":new BSON.ObjectId("XXXXXXXXXXX")});
var data = request.XXXXXXX;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.