MongoDB:将所有在另一个集合中没有其对象ID的文档分组

发布于 2025-02-13 09:53:24 字数 2103 浏览 1 评论 0原文

因此,我们有一个销售网站,有一个小故障,有时购买订单不会去购物车。我的任务是创建一个查询,以在订单集合中找到所有文档,并具有开放状态,这些文档在任何文档中都没有其objectid,the Cart Collection在Cart Collection

Heres中都有订单中的文档的典范集合:

{
    "_id" : ObjectId("5c5dac90c7f16568a5df67e5"),
    "shipment" : {
        "invoice" : "",
        "carrying" : "",
        "billingDate" : null,
        "shipmentDate" : null,
        "internalID" : "",
        "externalID" : ""
    },
    "version" : NumberInt(0),
    "integrated" : false,
    "splited" : false,
    "totalValue" : NumberInt(0),
    "totalQty" : NumberInt(0),
    "mainSupplierOrder" : true,
    "id" : "",
    "shop" : ObjectId("5c5d88dcb60645517cf64990"),
    "supplier" : ObjectId("5c50bca84359b945410a2c2f"),
    "status" : "open",
    "config" : {
        "discount" : NumberInt(0),
        "paymentMethod" : "",
        "operation" : "100.01",
        "obs" : "",
        "conference" : false
    },
    "products" : [

    ],
    "history" : [

    ],
    "createdDate" : ISODate("2019-02-08T16:21:36.644+0000"),
    "lastModifiedDate" : ISODate("2019-02-08T16:21:36.644+0000"),
    "lastModifiedBy" : "user.name",
    "__v" : NumberInt(0),
    "isOpen" : true
}

以及CARTS集合中的文档的一个景象:

{
    "_id" : ObjectId("5c5de236b47d8ddf670a21e8"),
    "calc" : ObjectId("62b40160e0f39d6cf5d9e3e9"),
    "shop" : ObjectId("5c5d88dcb60645517cf64969"),
    "createdBy" : "[email protected]",
    "lastModifiedBy" : "user.name",
    "orderState" : "edit",
    "orders" : [
        ObjectId("5c5de26ab47d8ddf670a23b0"),
        ObjectId("62b1f84c2b9a7103926ab44c"),
        ObjectId("62b1f84c2b9a718e376ab449"),
        ObjectId("62b1f84c2b9a7130486ab444")
    ],
    "lastModifiedDate" : ISODate("2022-06-27T14:13:23.293+0000"),
    "createdDate" : ISODate("2019-02-08T20:10:30.460+0000"),
    "__v" : NumberInt(1)
}

我必须找到所有没有其objectId的打开订单,这些订单中没有objectid objectiD,the offers offerstate = field Orderstate = Edit,

请提前感谢您的任何帮助

so we have a sales site with a glitch that some times a buy order wont go to the shopping cart. I have the task of creating a query to find all the documents inside the orders collection, with a open status, that dont have their ObjectID inside any document, with orderState = edit, in the cart collection

Heres an exemple of a document in the orders collection:

{
    "_id" : ObjectId("5c5dac90c7f16568a5df67e5"),
    "shipment" : {
        "invoice" : "",
        "carrying" : "",
        "billingDate" : null,
        "shipmentDate" : null,
        "internalID" : "",
        "externalID" : ""
    },
    "version" : NumberInt(0),
    "integrated" : false,
    "splited" : false,
    "totalValue" : NumberInt(0),
    "totalQty" : NumberInt(0),
    "mainSupplierOrder" : true,
    "id" : "",
    "shop" : ObjectId("5c5d88dcb60645517cf64990"),
    "supplier" : ObjectId("5c50bca84359b945410a2c2f"),
    "status" : "open",
    "config" : {
        "discount" : NumberInt(0),
        "paymentMethod" : "",
        "operation" : "100.01",
        "obs" : "",
        "conference" : false
    },
    "products" : [

    ],
    "history" : [

    ],
    "createdDate" : ISODate("2019-02-08T16:21:36.644+0000"),
    "lastModifiedDate" : ISODate("2019-02-08T16:21:36.644+0000"),
    "lastModifiedBy" : "user.name",
    "__v" : NumberInt(0),
    "isOpen" : true
}

and an exemple of a document in the carts collection:

{
    "_id" : ObjectId("5c5de236b47d8ddf670a21e8"),
    "calc" : ObjectId("62b40160e0f39d6cf5d9e3e9"),
    "shop" : ObjectId("5c5d88dcb60645517cf64969"),
    "createdBy" : "[email protected]",
    "lastModifiedBy" : "user.name",
    "orderState" : "edit",
    "orders" : [
        ObjectId("5c5de26ab47d8ddf670a23b0"),
        ObjectId("62b1f84c2b9a7103926ab44c"),
        ObjectId("62b1f84c2b9a718e376ab449"),
        ObjectId("62b1f84c2b9a7130486ab444")
    ],
    "lastModifiedDate" : ISODate("2022-06-27T14:13:23.293+0000"),
    "createdDate" : ISODate("2019-02-08T20:10:30.460+0000"),
    "__v" : NumberInt(1)
}

I must find all open orders that dont have their ObjectID inside the orders field in the carts documents with the field orderState = edit

Thanks in advance for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文