MongoDB模型与嵌入式文档的一对多关系

时间:2018-09-03 09:00:18

标签: mongodb mongodb-query

我在mongoDB docs上找到了 这个例子。

   {   
    _id: "joe",
    name: "Joe Bookreader"  }

    {
       patron_id: "joe",
       street: "123 Fake Street",
       city: "Faketon",
       state: "MA",
       zip: "12345"
    }
    {
       patron_id: "joe",
       street: "1 Some Other Street",
       city: "Boston",
       state: "MA",
       zip: "12345"
    }

它还指出,您只能通过一个查询来检索完整的顾客信息。

但是如何?

  • db.patron.find()//否
  • db.patron.aggregate //也许

我想要这样的结果

{
   _id: "joe",
   name: "Joe Bookreader",
   addresses: [
                {
                  street: "123 Fake Street",
                  city: "Faketon",
                  state: "MA",
                  zip: "12345"
                },
                {
                  street: "1 Some Other Street",
                  city: "Boston",
                  state: "MA",
                  zip: "12345"
                }
              ]
 }

非常感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我明白了。如果有人正在寻找一对多的关系解决方案,这里就是

ax1.set_prop_cycle(marker=['o','s','x','+','*'], color=plt.rcParams["axes.prop_cycle"].by_key()["color"][:5])