I have created a pipeline that creates a usage report by user.
I wrote all the pipelines and tried to do a final merge, but I noticed that there was no field with a unique id to write at "on".
I tried to use $out
, but I couldn't because I want the collection to keep stacking without being covered.
I just want to keep inserting new ObjectId for my results.
$merge: {
into: "Report",
on: "?? don't have uniq field ... why we can't just make newId for each new documents!!",
whenMatched: "i just want to keep insert",
whenNotMatched: "insert",
}
My final documents looks like
name:"개발"
userId: ObjectId(6049eeb428398a115cf83404)
purchaseBundleCnt:230
purchaseBundlePriceSum:5769500
yyyymmdd:20211001
After considering several methods, I found that by concating yyyymmdd
and userId
, can create a unique id. But because it is not an ObjectID.Type
, it is not accepted in on
.