简体   繁体   English

将 Mongodb 集合中的实例保存为 Atlas 触发器函数中的字符串变量

[英]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.

相关问题 无法从 MongoDB Atlas Trigger 中的集合中读取数据 - Cant read data from collection in MongoDB Atlas Trigger *未捕获(承诺)TypeError :) 无法从 MongoDB Atlas 检索数组/集合 - *Uncaught (in promise) TypeError:) Unable to retrieve array/collection from MongoDB Atlas MongoDB Atlas axios.get() function 调用但不返回数据 - MongoDB Atlas axios.get() function calling but not returning data from .save() 实例在将数据从 JSON 文件(Insomnia)保存到我的 MongoDB Atlas 时不起作用 - .save() instance is not working while saving the data from the JSON file(in Insomnia) to my MongoDB Atlas 如何重命名mongodb图集中已经存在的集合? - How to rename collection which already exists in mongodb atlas? 无法连接到 mongoDB Atlas Cluster 内的特定数据库和集合 - Cant connect to specific database and collection inside mongoDB Atlas Cluster Mongodb Atlas 集合中没有收到数据,即使与应用程序建立了连接 - No data received in Mongodb Atlas collection, even though connection is established with app 如何将集合 A 中的字符串与 mongodb 中的集合 B 匹配 - How to match string from collection A with collection B in mongodb MongoDB Atlas - 从脚本创建和数据库 - MongoDB Atlas - Create and db from a script 我无法将数据保存到我的 mongodb Atlas 数据库 - I am unable to save data to my mongodb Atlas database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM