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

mongodump queryFile fails with regex

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Problem Description

      mongodump --queryFile requires a vaild JSON input file. When a regex statement is formatted as valid JSON this fails since it is no longer a vaild JSON expression.

      {{}}

      Steps to Reproduce

      Run mongodump with a query input file which contains a regex:

      {{mongodump "mongodb+srv://$sourceCluster.$sourceProject.mongodb.net/" --username="$sourceUser" --password="$sourcePwd" --db <dbname> --collection <collection name> --queryFile ./queryfile.json --archive=collectionDump.dump }}

      queryfile with a vaild query (tested in compass)
      this file fails to run due to invalid JSON, the query it self is fully functioning in compass

      { "$or": [{

      "devicemac":

      { "$regex": /^01:01:01:03:FF:/ }

      },{
      "devicemac":

      { "$in": [ "01:01:01:01:01:0F", "01:01:01:01:01:15", "01:01:01:01:01:2B" ]}

      }]}

      queryfile with a vaild JOSN
      this file is processed to run but the end result is in incorrect
      only change put the parameter for $regex into quotes. This makes it valid JSON but an invalid regex.

      { "$or": [{
      "devicemac": {
      "$regex": "/^01:01:01:03:FF:/"
      }
      },{
      "devicemac":

      { "$in": [ "01:01:01:01:01:0F", "01:01:01:01:01:15", "01:01:01:01:01:2B" ]}

      }]}

      Expected Results

      mongodump should dump only these documents which fit to the query which was successfully tested in compass - this query is copied to a queryfile and passed to mongodump as parameter

      Actual Results
      the query with   "$regex": /^01:01:01:03:FF:/   works correct in compass and provides a correct amount of documents but is not accepted from mongodump as valid JSON.

      the query with   "$regex": "/^01:01:01:03:FF:/"   does not provide a correct amount of documents since it is invalid regex but is accepted from mongodump as valid JSON.

       

            Assignee:
            tim.fogarty@mongodb.com Tim Fogarty
            Reporter:
            michael.hoeller@akazia.de Michael Höller
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: