New to MongoDB, very new to Atlas. I’m trying to set up a trigger such that it reads all the data from a collection named Config. This is my attempt:
const mongodb = context.services.get(“Cluster0”);
const db = mongodb.db(“TestDB”);
var collection = db.collection(“Config”);
config_docs = collection.find().toArray();
console.log(JSON.stringify(config_docs));
the function is part of an automatically created realm application called Triggers_RealmApp, which has Cluster0 as a named linked data source. When I go into Collections in Cluster0, TestDB.Config is one of the collections.
Some notes:
- it’s not throwing an error, but simply returning
{}. - When I change
context.services.get("Cluster0");to something else, it throws an error - When I change
"TestDB"to a db that doesnt exist, or"Config"to a collection which doesn’t exist, I get the same output;{} - this is a verbatim copy of my question on stack: javascript - Cant read data from collection in MongoDB Atlas Trigger - Stack Overflow