猫鼬查找查询以执行多个条件

时间:2021-01-13 07:05:56

标签: node.js mongodb mongoose

我有两个表 vendor 和 vendorOrg 表。我需要返回基于 vendorOrg 表标准明智和类别明智的列表

const vendors = [{
  "name" : "Alfred",
  "location" : "FH",
  "vendorOrgId" : "1"
},
{
  "name" : "Alfred",
  "location" : "ADH",
  "vendorOrgId" : "2"
},
{
  "name" : "Alfred",
  "location" : "AFF",
  "vendorOrgId" : "41"
}]

const vendorOrg = [
  {
    "orgName" : "star super market",
    "vendorOrgId" : "1",
    "category" : "grocery",
    "status" : "active"
  },
  {
    "orgName" : "L.f super market",
    "vendorOrgId" : "41",
    "category" : "grocery",
    "status" : "active"
  },
  {
    "orgName" : "Fresh mart",
    "vendorOrgId" : "2",
    "category" : "Milk",
    "status" : "active"
  }
]

在下面找到条件, 1.vendor 的表vendorOrgId 必须与vendorOrg 的表id 相同。 2. vendorOrg 表状态应该是活动的。 如果上述条件为真,则我需要一个基于 vendorOrg 表类别的供应商列表类别。

{
    "grocery": [{
            "name": "Alfred",
            "location": "FH",
            "vendorOrgId": "1"
        },
        {
            "name": "Alfred",
            "location": "AFF",
            "vendorOrgId": "41"
        }
    ],
    "milk": [{
        "name": "Alfred",
        "location": "ADH",
        "vendorOrgId": "2"
    }]
}

这可能与猫鼬有关吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

  • from tkinter import * window = Tk() window.state('zoomed') window.configure(bg = 'white') def drag(event): new_x = event.x_root - window.winfo_rootx() new_y = event.y_root - window.winfo_rooty() event.widget.place(x=new_x, y=new_y,anchor=CENTER) card = Canvas(window, width=10, height=10, bg='blue2') card.place(x=300, y=600,anchor=CENTER) card.bind("<B1-Motion>", drag) another_card = Canvas(window, width=10, height=10, bg='red3') another_card.place(x=600, y=600,anchor=CENTER) another_card.bind("<B1-Motion>", drag) window.mainloop() 使用 vendorLog 收集并将 $lookup 传递给查找管道
  • vendorOrgId 必需条件
  • $match 显示必填字段
  • $project 解构 $unwind 数组
  • org by $group 并构造 org category 数组
  • vendors by null 并以键值格式构造数组
  • $group 将键值对数组转换为对象
  • $arrayToObject 将对象替换为 root
$replaceRoot

Playground