here's a simple aggregation that use to work and suddenly stopped, with the error
errmsg" : "insert for $out failed: { lastOp: { ts: Timestamp 1527170631000|78, t: 7 }, connectionId: 43852, err: \"E11000 duplicate key error collection: clients.tmp.agg_out.40 index: id dup key: { : ObjectId('5acdffd3957803129542e4b0') }\", code: 11000, codeName: \"DuplicateKey\", n: 0, ok: 1.0 }
db.collection.aggregate(
{$match:{'events':{$elemMatch:{'field1':1,'field2':2}}}},
{$unwind:'$events'},
{$match:{'events.field1':1,'events.field2':2}},
{$project:{'field3':'$events.field3'}},
{ $out : "results" }
)
I am not comparing _id fields nor projecting any _id values. The collection 'results' is dropped before I run the aggregation, so it is empty. Where is the duplication???