AbsoluteSith
AbsoluteSith

Reputation: 1967

Error while using context in Mongo-Atlas Stitch

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?

Upvotes: 2

Views: 1173

Answers (2)

Sr Jefers
Sr Jefers

Reputation: 129

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.

Upvotes: 0

AbsoluteSith
AbsoluteSith

Reputation: 1967

Ok this was silly.

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

Upvotes: 4

Related Questions