Re: Finding indexed subobjects.

8 views
Skip to first unread message

Jeremy Mikola

unread,
Aug 20, 2012, 5:53:59 PM8/20/12
to mongod...@googlegroups.com
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'...

By opting to store photos as nested objects, instead of an array of objects, you forfeit the ability to search array values or utilize multi-key indexes.

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.

Reply all
Reply to author
Forward
0 new messages