【问题标题】:How to increase BSON limit Size如何增加 BSON 限制大小
【发布时间】:2021-10-14 14:49:22
【问题描述】:

我正在为我的收藏“拍卖”中的 100k 条记录重写聚合代码,我需要创建函数以供另一个堆栈溢出指南参考

How to increase mongodb BSON document size

但出现错误

error TS2559: Type '(err: any, auctions: any) => void' has no properties in common with type 'CollectionCreateOptions' 

如何在 mongoDB 中获得超过 16MB 的 BSON 限制中的 10 万条记录

我的代码

db.collection("auctions",   (err: any, auctions: any): any => {
                    if(err) throw err;
                    const result: any = [];

                    const cursor: any = auctions.aggregate(
                        [
                            {
                                $match: {
                                    status: 'UNPAID'
                                }
                            },
                            {
                                $lookup: {
                                    from: 'bids',
                                    let: { id: '$_id' },
                                    pipeline: [
                                        {
                                            $match: {
                                                $expr: { $and: [{ $eq: ['$auctioncode', '$$id'] }] },
                                            },
                                        },
                                    ],
                                    as: 'bids',
                                },
                            },
                            {
                                $facet: {
                                    products: [{ $skip: 0 }, { $limit: 100000 }],
                                },
                            }
                        ],
                        {
                            "allowDiskUse": true,
                            "cursor": { "batchSize": 20 }
                        }
                    );


                    cursor.on("data",(data: any) => {
                        result.push(data);
                    });

                    cursor.on("end",() => {
                      return result;
                    })
                })

【问题讨论】:

    标签: mongodb mongoose node-mongodb-native


    【解决方案1】:

    问题是$facet 正在将所有 100k 文档拉入文档内的单个数组中。

    如果删除$facet阶段,并在管道末尾使用$skip和$limit阶段,它将通过游标返回100k个文档而不会超过限制。

    当然,除非您在管道中有一个大于 16MB 的文档。

    【讨论】:

    • 这适用于相同的聚合权@joe
    猜你喜欢
    • 2016-07-14
    • 2023-02-15
    • 2019-02-27
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多