将一个新对象推入一个数组mongodb的每个对象

时间:2017-07-07 09:53:09

标签: node.js mongodb mongodb-query

这是我的文件

 {  
   "_id":"595a069cc3e06d0fc0e214c5",
   "username":"RReddy",
   "sellingpoints":[  
      {  
         "_id":"595b500a7c4dc0663a29af4c",
         "selling_p_settings":[  
            {  
               "_id":"595a069cc3e06d0fc0e21492",
               "heatoilvalue":"off",
               "dieselvalue":"on",
               "benzinvalue":"on"
            },
            {  
               "_id":"595a069cc3e06d0fc0e21493",
               "heatoilvalue":"on",
               "dieselvalue":"on",
               "benzinvalue":"on"
            }
         ]
      },
      {  
         "_id":"595b500a7c4dc663a29af4c",
         "selling_p_settings":[  
            {  
               "_id":"595a069cc3e06d0fc021492",
               "heatoilvalue":"off",
               "dieselvalue":"on",
               "benzinvalue":"on"
            },
            {  
               "_id":"595a069cc3e06dfc0e21493",
               "heatoilvalue":"on",
               "dieselvalue":"on",
               "benzinvalue":"on"
            }
         ]
      }
   ]
}

希望实现如下 正如您在下面的文档中看到的那样,相同的对象被添加到数组的所有对象

{  
   "_id":"595a069cc3e06d0fc0e214c5",
   "username":"RReddy",
   "sellingpoints":[  
      {  
         "_id":"595b500a7c4dc0663a29af4c",
         "selling_p_settings":[  
            {  
               "_id":"595a069cc3e06d0fc0e21492",
               "heatoilvalue":"off",
               "dieselvalue":"on",
               "benzinvalue":"on"
            },
            {  
               "_id":"595a069cc3e06d0fc0e21493",
               "heatoilvalue":"on",
               "dieselvalue":"on",
               "benzinvalue":"on"
            },
{  //new object
               "_id":"4545454545",
               "heatoilvalue":"on",
               "dieselvalue":"on",
               "benzinvalue":"on"
            }
         ]
      },
      {  
         "_id":"595b500a7c4dc663a29af4c",
         "selling_p_settings":[  
            {  
               "_id":"595a069cc3e06d0fc021492",
               "heatoilvalue":"off",
               "dieselvalue":"on",
               "benzinvalue":"on"
            },
            {  
               "_id":"595a069cc3e06dfc0e21493",
               "heatoilvalue":"on",
               "dieselvalue":"on",
               "benzinvalue":"on"
            },
{   //new object
               "_id":"4545454545",
               "heatoilvalue":"on",
               "dieselvalue":"on",
               "benzinvalue":"on"
            }
         ]
      }
   ]
}

我只使用nodejs btw。

我可以通过MongoDB的聚合框架实现这一目标吗?

我是mongodb的新手

0 个答案:

没有答案