Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-2024

mongoimport merge option only update the first matched document

    XMLWordPrintable

    Details

    • Type: Question
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Done
    • Affects Version/s: 3.6.3
    • Fix Version/s: None
    • Component/s: mongoimport
    • Labels:
      None
    • Environment:
      Oracle Linux Server release 6.9

      Description

      Background: state-owned company in Indonesia is struggling in paying Oracle DB licenses and wants to migrate to other technology. We are proposing MongoDB as the solution. In 2 days we are coming down to introduce customer what MongoDB is capable of. One of question the customer will ask for sure is how to migrate their existing Oracle DB to MongoDB.

      I have 1 json file, hr_jobs.json. I imported from Oracle HR.JOBS table. My collection, employees, has 107 rows populated from Oracle HR.EMPLOYEES table. HR.JOBS and HR.EMPLOYEES has 1 to N relation in Oracle.

      Let's say currently employees collection has following data:
      db.employees.find(

      {"job_id": "SH_CLERK"}

      ,

      {"_id": 0,"employee_id": 1, "job_id": 1}

      ).limit(2)

      { "employee_id" : 198, "job_id" : "SH_CLERK" } { "employee_id" : 199, "job_id" : "SH_CLERK" }

      And, following is from jobs json file:
      [mongodb@mongodb3 bigcloud_dir]$ grep SH_CLERK hr_jobs.json,

      {"job_id":"SH_CLERK","job_title":"Shipping Clerk","min_salary":2500,"max_salary":5500}

      They are matching in job_id. But every time I run mongoimport --mode merge, it can only update/add the first document (employee_id: 198), and skip employee_id: 199.

      Command I used:
      mongoimport --db "hr" --collection "employees" --file hr_jobs.json --mode merge --upsertFields job_id --jsonArray

      The expected result is to update all employees documents when job_id matches with employee_id in json file. In this case, add job_title, min_salary and max_salary fields into ALL employees documents, not just one doc.

      Really appreciate any comments/pointers.

        Attachments

          Activity

            People

            Assignee:
            kelsey.schubert Kelsey T Schubert
            Reporter:
            hsjarbin Habiburrokhman Sjarbini
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: