Reorder MongoDB Document Fields

 From MongoDB Compass --> Open MongoDB shell:

db.MY_COLLECTION_NAME.updateMany({}, [
  {$replaceWith: {
    $mergeObjects: [
      {
        "_id": "$_id",
        "field1": "$field1",
        "field2": "$field2"
      },
      "$$ROOT"
    ]
  }}])

Specify the fields in the block in the order you want them.
Note this works with arrays and all data types.

Comments

Popular posts from this blog

Unity: VR Head Blocking (Steam VR v2)

StyleGAN3 Setup

Photoshop: Create Seamless Textures