I'm attempting to set a unique index on a field within a subarray of a collection in MongoDB. This index will also be set to drop existing dupes. I'm following the MongoDB documentation, but it does not seem to be working (dupes still exist in my db). I believe my issue may be how I'm attempting to access the document within the 'photos' sub-array. Below is my schema and the code I'm trying to use to set the index:
{
event: String,
headline: String,
city: String,
state: String,
date: String,
start: String,
end: String,
dateState: String,
radius: String,
team_1: String,
team_2: String,
object_id: String,
longitude: String,
latitude: String,
cover: {
img: String,
username: String
},
photos: [{
img: String,
link: String,
username: String,
profile: String,
text: String,
longitude: String,
latitude: String,
created_time: String
}]
}
gameday.events.ensureIndex( {"photos.img": 1}, { unique: true, dropDups: true } )