0

I am loading data from a mongodb collection to a mysql table through Kettle transformation. First I extract them using MongodbInput and then I use json input step. But since json input step has very low performance, I wanted to replace it with a javacript script. I am a beginner in Javascript and even though i tried somethings, the kettle javascript script is not recognizing any keywords.

can anyone give me sample code to convert Json data to different columns using javascript?

jacktrade
  • 3,125
  • 2
  • 36
  • 50
Deepthi
  • 79
  • 1
  • 7

2 Answers2

1

To solve your problem you need to see three aspects:

  1. Reading from MongoDB
  2. Reading from JSON
  3. 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.

ATN
  • 665
  • 8
  • 26
0

you could use the json input step to get the values of this json and put in common rows

jacktrade
  • 3,125
  • 2
  • 36
  • 50
  • Guess this will not help me , because I do not want output in json format and more over both json input and output steps are very slow.So I need to write a javascript to speed up the process. – Deepthi Oct 11 '13 at 15:05
  • use the json input step as NOT FINAL step. I mean, you use this step and now you have rows that you can process normally with other steps. I dont get the concept "output steps are very slow". I use this steps daily without noticing worst performance than javascript steps. – jacktrade Oct 11 '13 at 15:54
  • sorry i made a mistake, i mean json INPUT step – jacktrade Oct 11 '13 at 15:57