Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: MongoDB Output plugin - how to update by querying _id field ?

  1. #1
    Join Date
    Jul 2016

    Default MongoDB Output plugin - how to update by querying _id field ?


    I am trying to update a mongodb document by specifying _id field for the query match. I am using mongodb output component.
    I am not able to specify the query criteria as below

    {"_id" : ObjectId("579c18b47f34b4330f85a981")}

    Instead the query is getting created as

    {"_id" : "579c18b47f34b4330f85a981"}

    with this query is not finding the document, and the update operation fails with the error No fields to update have been specified for modifier update operation!

    am getting the id to be passed as a string from the previous step, and setting _id as the match criteria in the "Mongo Document Fields" tab.

  2. #2
    Join Date
    Oct 2016


    OK Everyone, I've FINALLY figured this out!

    1. MongoDB Import: Set it up as you would expect
    2. More transformations!!!!
    3. Modified Java Script Value:
      • Add the following code: var _newId = "{ '$oid': '" + _id + "' }";
      • Set up an output mapping at the bottom.
        • Fieldname: _newId
        • Rename to: _id
        • Replace value 'Fieldname' or 'Rename to': Y

    4. More transformations if desired!!!
    5. MongoDB Output:

    • Set _id up:
      • Use field name: Y
      • NULL values: Ignore
      • JSON: Y <------------------------------------------------ This is the trick!!!!
      • Match field for update: Y <----- tells PDI to use for querying
      • Modifier operatino: N/A

    Now when you look at your field mapping output (press SPACEBAR on the MongoDB Output), you'll see it listed as a JSON Document.

    You should now be good to upsert!


    Mongo (via Docker) 3.2.8, no auth (all for testing purposes)
    PDI version: pdi-ce-

    PS, this is literally the worst forum software I've ever used. There is ZERO formatting....
    Last edited by drewlover; 10-12-2016 at 03:41 PM. Reason: I figured it out!

  3. #3
    Join Date
    Jan 2018


    Thank you!

    I was just googling for this exact situation.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.