2

I'm trying to create a stitch for a Mongo-Atlas cluster.

Here is the simple webhook function

exports = function(payload) {
   const mongodb = context.services.get("mongodb-atlas");
   const cyber = mongodb.db("cyber"); 

};

unfortunately running this gives me the error

TypeError: Cannot access member 'db' of undefined

trace: TypeError: Cannot access member 'db' of undefined at exports (function.js:4:18) at apply () at function_wrapper.js:3:10 at :12:1

Basically the first get call returns mongodb as undefined.

Anybody has run into this issue?

AbsoluteSith
  • 1,917
  • 25
  • 60
  • I ran into it today and for me it still doesn't work. I check couple of times that I'm in correct Atlas cluster but I'm still getting the same error. – Lukas Luke Stateczny Nov 13 '20 at 10:32

2 Answers2

4

Ok this was silly.

The context name for my cluster was not "mongodb-atlas" but rather "mongodb-atlas-production"

AbsoluteSith
  • 1,917
  • 25
  • 60
  • A comment in the trigger editor when you first start writing your trigger says the following: "Note: In Atlas Triggers, the service name is defaulted to the cluster name." For me it worked to use my cluster name as the service name. – Dave Stevens May 26 '20 at 19:08
0

If you are at MongoDb-Atlas, u can try first reading the documentation appended in your function definition.

Functions run by Triggers are run as System users and have full access to Services, Functions, and MongoDB Data. [...] Note: In Atlas Triggers, the service name is defaulted to the cluster name.

It means that your SERVICE_NAME is the name of your Cluster.

Sr Jefers
  • 87
  • 4
  • 14