3
votes

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

1
As of now got it working by passing the Shard Keys instead of _id . But still if i had to search by _id , how would i specify it in the query, using the PDI Kettle - MongoDB Output component ?Mahesh

1 Answers

2
votes

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.