Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2618

validation problem with replica set

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.16
    • Affects Version/s: None
    • Component/s: None

      I'm using mongoid 3.0.14, replica set, safe:true and consistency:eventual.

      My model has a boolean field with a validates_uniqueness_of :active, :if => :active
      (only one record should be :active = true)

      My controller does something like this..
      model = Model.with(consistency: :strong).find(params[:id])
      Model.update_all(:active => false)
      model.active = true
      model.save

      sometimes 'save' operation returns an error "active field already in use".

      that seems strange for me. I dont understand how validation works, but the only thing I could imagine is that mongoid is validating on secondary during save operation.

      when I force the save code to primary "model.with(consistency: :strong).save" that error does not occur anymore.

      if I'm correct this must be a bug. Validations on save should be on primary node (replicas + validation).

            Assignee:
            Unassigned Unassigned
            Reporter:
            kinfante kinfante
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: