Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: mongodb output - insert into array

  1. #1
    Join Date
    Nov 2013
    Posts
    4

    Default mongodb output - insert into array

    Hi,

    i have a problem inserting data into an array at mongodb output.

    i have the following data:

    customer_id, order_id, order_date, quantity
    123, 222,2012-03-03,1
    123, 333,2013-08-09,4

    i have checked upsert and specified customer_id as field used for upsert.

    i want to created an array (sales) with the list of orders.

    requested output:
    customer_id,
    sales (array including two order records)

    when i specify sales as mongo document path for order_id, order_date and quantity
    then it inserts two records (containing an one element array)
    instead of inserting one record with a two element array

    Can i do the above? what i am doing wrong?

    this would be the first step, the second would be that that i update also the elements of the array, but even the simple version does not work yet.

    thanks for the replies in advance
    Last edited by ztalas; 11-05-2013 at 11:43 AM.

  2. #2
    Join Date
    Feb 2013
    Posts
    15

    Default

    set 'match field for upsert'=Y for customer_id field .

    select the appropriate modifier option. ($push for order related fields) - and modifier policy can be insert & update

    Please post the jSON doc structure
    Thanks & Regards,
    Siby

  3. #3
    Join Date
    Nov 2013
    Posts
    4

    Default

    Hi,

    i was able to solve the above problem and now it is inserting a two element array. now i should check whether the array element already exists if yes update if no insert.

    this is my table input:

    select '123' partner_customer_id, '222' order_id, '1' quantity union all
    select '123' parner_customer_id, '333' order_id, '2' quantity

    and this is my mongo output:


    Name Mongo document path Use field name Match field for upsert Modifier operation Modifier policy
    partner_customer_id Y Y N/A Insert
    partner_customer_id Y N N/A Insert
    order_id sales[0] Y N $set Insert
    order_id sales[1] Y N $push Update
    quantity sales[0] Y N $set Insert
    quantity sales[1] Y N $push Update


    When running the above it inserts a customer record with an two element array. if running it again there will be a customer record with an 4 element array, etc.

    But i want to reach that it updates the array elements as well based on the order_id field. eg the quantity changes from 1 to 4 then it updtes the quantity, but array element remains the same only change: quantity is updted in the relevant element. It is possible to do this in pentaho?

    thanks in advance


    since original problem is answered i am opening a new thread for this
    Last edited by ztalas; 11-06-2013 at 06:30 AM.

  4. #4
    Join Date
    Nov 2013
    Posts
    4

    Default

    Quote Originally Posted by siby.abin View Post
    set 'match field for upsert'=Y for customer_id field .

    select the appropriate modifier option. ($push for order related fields) - and modifier policy can be insert & update

    Please post the jSON doc structure

    thanks for the reply, please find the solution for the problem in the post. although now comes the real problem. details attached

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.