-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
When using custom ids and saving a document that has an id that already matches a saved document, the save fails but says it succeeds. No error is raised, and the document reports being persisted, but nothing is actually saved to the db.
Here's a simple example:
class Day
include Mongoid::Document
field :_id, type: Date, default: ->
field :note, type: String
end
Day.count # 0
d1 = Day.new note: "d1"
d1.id # Sun, 27 Oct 2013
d2 = Day.new note: "d2"
d2.id # Sun, 27 Oct 2013
d1.save # returns true
Day.count # 1
d2.save # also returns true. No error is raised.
d2.persisted? # true – says it's persisted... but...
Day.count # still 1
Day.find(Date.today).note # "d1" – only the first document was saved