0

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" => []
                        }
                    ]
                }
            ]
        }
    ]
}
Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215
  • Atomically you cannot unless you know what indexes everything sits at, which you don't – Sammaye Sep 11 '13 at 12:52
  • What options do I have? – Christian Fazzini Sep 11 '13 at 12:54
  • 1
    At the moment, pulling the document out and updating it in your client code and then saving it again, this does mean there can be race conditions and you could be updating a stale document, but it is currently the only method – Sammaye Sep 11 '13 at 12:58

0 Answers0