Get data from mongo cluster to realm function

I am trying to get data from collection to realm function but getting only object object

     const cluster = context.services.get("mongodb-atlas");
   const users = cluster.db("ssn").collection("invites");
   const stories = cluster.db("ssn").collection("stories");
   const twilio = context.services.get("Twilio");
   
   
   const story = await stories.find({});
 console.log(story);

Hi @Jayesh_Sharma,

You are missing the toArray() and the parsing:

Try this:

exports = function(arg){
    const collection = context.services.get("mongodb-atlas").db("test").collection("test");
    collection.find({}).toArray().then((docs) => {
      console.log(EJSON.stringify(docs));
    });
};

Cheers,
Maxime.

1 Like

hii @MaBeuLux88 , it displays only first data not all.

My function above prints all the documents in the test.test collection.

Make sure you are not using findOne() instead of find() or something like that. Also the query might be filtering more than you think?

@MaBeuLux88 , I am using the same you have told me.