Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: Mongodb update

  1. #1

    Arrow Mongodb update

    Hello. This is my first post in this forum and i not familiarized with the forum rules. Sorry if something is wrong.

    I can´t update mongodb document like i want.

    this is the situation: I have a document in db that have to fields which are the key fields (like a compose key). In datastream i have this

    Code:
    key1, key2, New York, New york dataA1, New York dataA2
    key1, key2, New York, New york dataB1, New York dataB2
    key1, key2, Orlando, Orlando dataA1, Orlando dataA2
    key1, key2, Orlando, Orlando dataB1, Orlando dataB2
    ....
    
    And other similar.
    Now I need to Insert/update to get this structure on mongodb:


    Code:
    
    {
       fieldkey1: key1,
       fieldkey2: Key2,
       cities : [
                   {
                    name : New York
                    data: [
                                 { 
                                   data1 : New York dataA1,
                                   data2 : New York dataA2
                                  },
                                  { 
                                   data1 : New York dataB1,
                                   data2 : New York dataB2
                                  }
                            ]
                    },
                    {
                    name : Orlando
                    data: [
                                 { 
                                   data1 : Orlando dataA1,
                                   data2 : Orlando dataA2
                                  },
                                  { 
                                   data1 : Orlando dataB1,
                                   data2 : Orlando dataB2
                                  },
                                  ....
                            ]
                    }
    
                ]
    }
    I have test a lot of combinations with document/array structures and modifier policies but can´t do this.

    In this place http://wiki.pentaho.com/display/EAI/MongoDb+output there is an example a lot of similar to my problem at point 2.4.1 (seem that the data stream structure is equals) but when i clone it, the step creates a new (root) document for each city, duplicating key fields. I had spend a lot of hours trying to solve this problem but no result until now.

    Thanks.

  2. #2
    Join Date
    Aug 2006
    Posts
    1,741

    Default

    Hi,

    If this document structure needs to be created and updated then its just not possible to do with the step as it stands with just one pass over the input data. You have a structure that has two arrays that need to be created and pushed to. This would require two sets of match conditions which can't be done in the step at present. The first would require matching on just "fieldkey1" and "fieldkey2". If this match failed then the initial record structure with top level "cities" array and sub array "data" could be created (and populated with the first element of each respective array) using the insert modifier policy and $set operation. A match on fieldkey1 and fieldkey2 could then use update policy in conjunction with $push to push a new city to the end of the cities array. However, you also (at the same time) want to be able to $push to the end of the appropriate "data" array - this requires matching on "name" as well as "fieldkey1" and "fieldkey2". This can be done using the positional operator "$" to update the correct entry in the "cities" array. We can do one, but not both, of these two matching conditions at any one time.

    I think the only way to achieve your final result would be to make two passes in order to fully populate each document. The first pass would use the first matching scenario and push cities into the "cities" array (each with an initial entry in its "data" array). The second pass would use the second matching scenario and $push additional entries to the end of each city's "data" array.

    Cheers,
    Mark.

  3. #3

    Default

    Hi, thanks a lot.

    I supposed that the problem could be solved in this way and next to the post i did this:

    Name:  towSteps.jpg
Views: 131
Size:  7.5 KB

    I also think this is the only way. Thanks for confirm to me

  4. #4
    Join Date
    Dec 2017
    Posts
    10

    Default

    Did you solve this issue? I have the same problem. Can you help me?

  5. #5
    Join Date
    Dec 2017
    Posts
    10

    Default

    Can you post an example of the transformation?
    bests regards

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.