Daniil Motsniy
Daniil Motsniy

Reputation: 27

Parse data from MondoDB Atlas

I am trying to get some values from DB in cluster (MongoDB). Using Stitch.

Now I have this to get data.

const client = stitch.Stitch.initializeDefaultAppClient('application-...');
const db_data = client.getServiceClient(stitch.RemoteMongoClient.factory, 'mongodb-atlas').db('Name').collection("Name");
data = db_data.find({}, {}).asArray();
console.log(data);

It looks like.

enter image description here

But I can`t realize how to parse it to JSON or just put some values to variables.

Upvotes: 0

Views: 42

Answers (1)

alexalexalex09
alexalexalex09

Reputation: 61

The find function returns a promise, which is what you see in your posted image. You need to handle that promise with .then() like the following:

const client = stitch.Stitch.initializeDefaultAppClient('application-...');
const db_data = client.getServiceClient(stitch.RemoteMongoClient.factory, 'mongodb-atlas').db('Name').collection("Name");
data = db_data.find({}, {}).asArray().then((data) => console.log(data));

Here's a relevant example for you!

Upvotes: 1

Related Questions