feliixx / mongoplayground

a simple sandbox to test and share MongoDB queries
https://mongoplayground.net
GNU Affero General Public License v3.0
180 stars 11 forks source link

`mgodatagen`: Can't have an `enum` of `ObjectId`s? #128

Closed rickhg12hs closed 2 years ago

rickhg12hs commented 2 years ago

Shouldn't it be possible to have an enum of ObjectIds in the mgodatagen configuration?

I ran into this on mongoplayground.net:

[
  {
    "collection": "collection",
    "count": 10,
    "content": {
      "key": {
        "type": "enum",
        "in": [
          ObjectId("624ac834820a8747b065a561"),
          ObjectId("624ac834820a8747b065a562"),
          ObjectId("624ac834820a8747b065a563"),
          ObjectId("624ac834820a8747b065a564"),
          ObjectId("624ac834820a8747b065a565")
        ]
      }
    }
  }
]

... but this produced an error:

error in configuration:
  error in configuration file: object / array / Date badly formatted: 

        invalid character 'O' looking for beginning of value
feliixx commented 2 years ago

Hi @rickhg12hs,

you can't use MongoDB extended JSON v1 notation in mgodatagen, but you can use [MongoDB extended JSON v2]() ( which is valid JSON) like this :

[
  {
    "collection": "collection",
    "count": 10,
    "content": {
      "key": {
        "type": "enum",
        "values": [
          {
            "$oid": "624ac834820a8747b065a561"
          },
          {
            "$oid": "624ac834820a8747b065a562"
          },
          {
            "$oid": "624ac834820a8747b065a563"
          },
          {
            "$oid": "624ac834820a8747b065a564"
          },
          {
            "$oid": "624ac834820a8747b065a565"
          }
        ]
      }
    }
  }
]

see mongoplayground.net/p/j9XSjSADqke

rickhg12hs commented 2 years ago

Hi @feliixx,

Super! Now I know! :-)