迁移 liquibase 中的数据 MongoDB

Migrate datat MongoDB in liquibase

我有 mongo 2 个看起来像这样的集合:

集合 1:

{
"id": "someId",
"name": "someName"
}

colleciton2:

{
"_id": "id",
"objectOfTypeCollection1": [{
    "id": "someId2",
    "name": "someName2"
    }]
}

迁移后我需要: 集合 1:

{
"id": "someId",
"name": someName
},
{
"id": "someId2",
"name": "someName2"
}

这很容易通过一些 javascript 代码完成,但我需要在 Liquibase 中进行此迁移,这意味着使用 runCommand。到目前为止,我还不知道有一种方法可以在更新命令中使用 find 命令,以便设法将数据从 collection2.objectOfTypeCollection1 移动到 collection1。

说简单点,runCommand可以用JS吗?

使用$merge

db.runCommand( {
   aggregate: db.collection2.getName(),
   pipeline: [ 
   {  $unwind: "$objectOfTypeCollection1" },
   {
      $merge: {
         into: db.collection1.getName()
      }
   } 
   ],
   cursor: {}
} )