How can i update the ids field?

64 views Asked by At

Unfortunately, I cannot use positional operators since there is a bug that doesn't allow deeper than 1 embedded document: https://jira.mongodb.org/browse/SERVER-831

So this wont work (using the Mongodb Ruby driver):

  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] } })

Given the following collection. Relationships is embedded in dates, dates is embedded in providers.

How do I update the ids field?

{
           "_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

There are 0 answers