add_to_set does not work with array of hashes/embedded documents

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Add_to_set does not work with array of hashes/embedded documents.
      For example:

      Model.create().add_to_set(data: [{a: 1}])
      

      gives:

      NoMethodError: undefined method `metadata' for {:a => 1}:Hash
      

      and

      Model.create().add_to_set(data: [EmbeddedModel.new])
      

      gives:

      NoMethodError: undefined method `__bson_dump__' for #<EmbeddedModel:>
      

      workaround:

      m = Model.create()
      Model.collection.find(_id: m._id).update_all("$addToSet" => { data: {'$each' => [{a:1},{b:2}]} })
      

              Assignee:
              Emily Stolfo (Inactive)
              Reporter:
              Jurriaan Pruis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: