On Monday, August 20, 2012 4:03:13 PM UTC-4, nightarcherbr wrote:
The application must ensure that photo.id_foto is unique inside the document, but should allow
duplicates inside the entire collection (That is why I'm using one object and not an array of photos)
And now I need to write update query that sets some data only where 'custom = 1'...
I realize you cannot create a unique index compounding the document ID and the ID of an embedded photo within an array (e.g. {_id:1, "
photo.id":1}), as each index entry (taking multi-key into account) will refer to the same document and not cause a constraint violation.
Since the photo objects are embedded, it would probably be best to simply handle the uniqueness check in your application and store the embedded photo documents in an array. That would allow you to query by "photo.custom" and use the
$ positional operator appropriately.