如何在mongoDb

时间:2016-01-13 08:38:08

标签: mongodb database nosql

我需要在mongoDb中为现有集合添加数据数组。

假设我现有的收藏品,比如" planetSystem"是类型:

{
     "_id":"123123123",
     "key1":"value1",
     "key2":"value2" 
}

我需要添加以下类型的数组

[
    {
        "amount":"678",
        "addedBy":"idontknow"
        "commission":"100"
    } ,
    {
        "amount":"800",
        "addedBy":"iwishiknew"
        "commission":"108"
    } 
]

这样最终的集合看起来像这样

{
    "_id":"123123123",
    "key1":"value1",
    "key2":"value2",
    [
      {
        "amount":"678",
        "addedBy":"idontknow"
        "commission":"100"
      } ,
      {
        "amount":"800",
        "addedBy":"iwishiknew"
        "commission":"108"
      }
    ] 
}

我需要更新查询部分的帮助。 感谢

1 个答案:

答案 0 :(得分:0)

您必须为PlanetSystem集合添加密钥

constraintTextView1Right.constant = 20
UIView.animateWithDuration(0.3) { () -> Void in
            self.view.layoutIfNeeded();//forcefully apply constraint with new values
        }

添加新密钥

var planetSystem= {
 "_id":"123123123",
 "key1":"value1",
 "key2":"value2" };

var arr = [{
    "amount":"678",
    "addedBy":"idontknow"
    "commission":"100"
} ,
{
    "amount":"800",
    "addedBy":"iwishiknew"
    "commission":"108"
}];

结果,

planetSystem.arr = arr;