title: Mongoid / Moped update an embedded document - ArgumentError - wrong number of arguments (2 for 1)
body: <p>I'm having trouble updating an embedded document in a Ruby / Sinatra app. I'm trying to use the positional operator "$" in an update statement in order to select the correct document from the embedded array. But this is throwing an "ArgumentError - wrong number of arguments (2 for 1)" error.</p>
  
  <p>A simple update statement with a hard-coded array index works fine. So maybe Mongoid/Moped doesn't support the position operator?... Although from what I could see, it looks like it should.</p>
  
  <p>Does anyone know what the best approach is? Is there some other way to determine sub-document index without iterating through them all using Ruby in my controller - which is plan B, but seems really flaky!...</p>
  
  <p>Here is my basic set up: I have "Customers"...</p>
  
  <pre><code>class Customer
      include Mongoid::Document
      field :customer_name, type: String
  
      embeds_many :contacts
  
      attr_accessible :customer_name
  end
  </code></pre>
  
  <p>... with embedded "Contacts"...</p>
  
  <pre><code>class Contact
      include Mongoid::Document
      field :first_name, type: String
  
      attr_accessible :first_name
  
      embedded_in :customer
  end
  </code></pre>
  
  <p>And in my controller I get the ._ids of both customer (pk), and the specific embedded document to update (contact_pk):</p>
  
  <pre><code>Customer.update(
                   { 
                     "_id" =&gt; Moped::BSON::ObjectId(pk),"contacts._id" =&gt; Moped::BSON::ObjectId(contact_pk)
                   },
                   {
                     $set =&gt; {"contacts.$.first_name" =&gt; "Bob" }
                   }
                  ) 
  </code></pre>