Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDI Kettle - How to specify ObjectId for query match in MongoDB Output

Using PDI Kettle MongoDB Output, I am trying to update a mongodb document, by querying the _id (ObjectId) field. If i pass the _id variable as String to the MongoDB Output step, the final query that gets created looks like

    Modifier update query:

{
  "_id" : "<string val>"
}

which might get transformed finally to something like

    Modifier update query:

{
  "_id" : "579c18b47f34b4330f85a981"
}

This might be causing the query not finding the document and update fails with error " No fields to update have been specified for modifier update operation! "

Is there any way i can specify the query as below ?

{"_id" : ObjectId(579c18b47f34b4330f85a981)}

Or am i seeing the error because of some other reason ?

Please find the screenshot of the "mongo document fields" tab. enter image description here

like image 368
Mahesh Avatar asked Nov 01 '25 13:11

Mahesh


1 Answers

First, you can use a "Javascript" step to transform the "_id" value in JSON format:

_id = '{ "$oid": "' + _id + '" }'

Then in the last row of "MongoDB output" step you should set the JSON attribute to Y.

like image 187
Hobbes Avatar answered Nov 03 '25 10:11

Hobbes