-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
It the 3.0.0rc release, trying to create two records with the same unique index, doesn't fail every time (even with safe: true).
class MyClass include Mongoid::Document field :my_field, type: String index({ my_field: 1 }, {unique: true, name: 'my_field'}) end MyClass.create_indexes
MyClass.create!(my_field: 'foo').with(safe: true) # => (correctly) returns the document MyClass.create!(my_field: 'foo').with(safe: true) # => (correctly) raises Moped::Errors::OperationFailure because of MongoDB E11000 duplicate key error MyClass.create!(my_field: 'foo').with(safe: true) # => returns a document! :/ MyClass.create!(my_field: 'foo').with(safe: true) # => (correctly) raises Moped::Errors::OperationFailure because of MongoDB E11000 duplicate key error
Note that only record actually reaches the database though.
MyClass.count # => 1