To solve your problem you need to see three aspects:
- Reading from MongoDB
- Reading from JSON
- Reading from (probably) String
Reading from MongoDB Except if you changed the interface, MongoDB returns not JSON but BSON files (~binary JSON). You need to see the MongoDB documentation about reading and writing BSON: probably something like BSON.to()
and BSON.from()
but I don't know it by heart.
Reading from JSON Once you have your BSON in JSON format, you can read it using JSON.stringify()
which returns a String
.
Reading from (probably) String If you want to use the capabilities of JSON (why else would you use JSON?), you also want to use JSON.parse()
which returns a JSON object.
My experience is that to send a JSON object from one step to the other, using a String
is not a bad idea, i.e. at the end of a JavaScript step, you write your JSON object to a String
and at the beginning of the next JavaScript step (can be further down the stream) you parse it back to JSON to work with it.
I hope this answers your question.
PS: writing JavaScript steps requires you to learn JavaScript. You don't have to be a master, but the basics are required. There is no way around it.