#StackBounty: #javascript #mongodb #mongodb-atlas Cant read data from collection in MongoDB Atlas Trigger

Bounty: 50

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:

exports = function(changeEvent) {
  const mongodb = context.services.get("Cluster0");
  const db = mongodb.db("TestDB");
  var collection = db.collection("Config");
  config_docs = collection.find().toArray(); 

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; {}
  • I’ve tried creating new Realm apps, manually creating services, creating new databases and new collections, etc. I keep bumping into the same issue.
  • The mongo docs reference promises and awaits, which I haven’t seen in any examples (link). I tried experimenting with that a bit and got nowhere. From what I can tell, what I’ve already done is the typical way of doing it.

TestDB database and Config collection
Linked Data Source:
Linked data source, Cluster0

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.