MongoDB - 将一个包含子文档数组的文档拆分为 2 个文档,每个文档中有一半的子文档

问题描述

大家好,

由于子文档数组中的项目数量我有一组文档达到了 BSON 大小限制。我正在尝试将新字段应用于这些子文档作为架构更新的一部分,但在这些特定文档上失败,因为新字段超过了 BSON 大小限制。

我想要做的是根据子文档数组有效地将文档分成“一半”,因此我将文档 1(原始)与数组现在包含(例如)子文档 1-2,和 Document1B 具有包含 3-4 的数组。

这是一个基本布局的例子

{ 
    "_id" : ObjectId("5f11d4c28663f32e940696e0"),"DocumentId" : "0000001","Items" : [
        {
            "ItemId" : NumberInt(1),"ItemType" : NumberInt(1),"Classtype" : "1","Created" : ISODate("2012-03-13T11:13:22.000+0000"),"LastUpdated" : ISODate("2020-03-12T15:52:39.000+0000") 
        },{
            "ItemId" : NumberInt(2),{
            "ItemId" : NumberInt(3),{
            "ItemId" : NumberInt(4),],"Priority" : NumberInt(0),"Status" : NumberInt(3),"FileChecksum" : "ca1fbd9c8e1669bcf4155657d3600fa4","CreatedBy" : "anonymous.user@test.com","LastUpdatedBy" : null,"AssignedBy" : "anonymous.user@test.com","DeletedBy" : null,"LastUpdated" : ISODate("2020-03-12T15:52:39.000+0000"),"Created" : ISODate("2012-03-13T08:13:23.000+0000"),"Assigned" : ISODate("2012-03-13T11:10:48.000+0000"),"Completed" : ISODate("2012-03-13T11:13:22.000+0000"),"DeletedDate" : null,"AssignedTo" : "anonymous.user@test.com","RejectionReason" : null,"Deleted" : false,"DeletionReason" : null
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)