Creating new collections and inserting data with Realm functions

Always when I try to insert any data into an existing collection or create a new collections I am getting an error saying that the function doesn’t exist.

I have tried getting the DB with

context.services.get(“mongodb-atlas”).db(“DAOs”)

and then appending .createCollection("foobar") but I get an error saying TypeError: 'createCollection' is not a function. I also tried using insertOne() which is supposed to create a new collection automatically but I am getting the same error.
Are there are working functions that I can use in Realm functions to insert data? Am I not getting the DB correctly? Thank you in advance

Hello David,

It seems that Realm is not finding the context service.

In order to be able to use a service, it must be defined first as a Data Source. Please log into the Realm UI for your application. Under the Manage menu, select Linked Data Sources and make sure that you have a link to the cluster with the name mongodb-atlas.

Hey,

thank you for your answer. It seems like it was already linked to the data source. What helped me fixing the problem though, was splitting the code into multiple parts. Here is what I changed it to

  const mongodb = context.services.get("mongodb-atlas");
  const db = mongodb.db("databaseName");
  const testCollection = db.collection("foobar");
  
  testCollection.insertOne("my entry");
  return;