문제

I have a company that contains products:

class Company
  include Mongoid::Document
  include Mongoid::Timestamps

  embeds_many :products

  index({"products.code" => 1}, {sparse: true, unique: true})

end

But when I create products(in the same parent) with the same code, like '123', the index does not check the uniqueness of it and it gets created normally. What is wrong?

도움이 되었습니까?

해결책

Unique indexes are not enforced in embedded documents. There's an open issue on this.

Also, check this page for some workarounds/approaches to enforce this.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top