我该如何更新ids字段?

时间:2013-09-11 12:48:36

标签: mongodb mongodb-ruby

不幸的是,我不能使用位置运算符,因为有一个错误不允许超过1个嵌入式文档:https://jira.mongodb.org/browse/SERVER-831

所以这不行(使用Mongodb Ruby驱动程序):

  stat_profile.update({ profile_id: profile.id, providers: { '$elemMatch' => { provider_name: 'foo', dates: { '$elemMatch' => { date: 20130911, relationships: { '$elemMatch' => { relationship_type: 'friend' } } } } } } },
  { '$set' => { 'providers.$.dates.$.relationships.$.ids' => [1,2,3] } })

鉴于以下收集。关系嵌入在日期中,日期嵌入在提供者中。

如何更新ids字段?

{
           "_id" => BSON::ObjectId('523048983858f61767000008'),
    "profile_id" => 3,
     "providers" => [
        [0] {
            "provider_name" => "foo",
                    "dates" => [
                [0] {
                             "date" => 20130911,
                    "relationships" => [
                        [0] {
                            "relationship_type" => "acquaintance",
                                        "count" => 0
                        },
                        [1] {
                            "relationship_type" => "friend",
                                        "count" => 0,
                                  "males_count" => 0,
                                "females_count" => 0,
                            "top_ten_countries" => [],
                                          "ids" => []
                        }
                    ]
                }
            ]
        }
    ]
}

0 个答案:

没有答案