I unfortunately found no simple option to identify the substring of the first three fields like index of the 3rd occurrence of “/” to pass this to $dateFromString. The rest I would have split and $addtoset.
Normally @Asya_Kamsky 's pages like Stupid Tricks with MongoDB are a gold mine of tricks unfortunately I haven’t found a cool idea this time.
Any one who has done something like this before? I should mention that three are appr. 10 Mio documents with ~20 array elements each to process - so I stayed (until now) away from too complex constructs.
Hello @Pavel_Duchovny
thanks for you thoughts, I actually tried $regexFind and also $split plus $arrayElemAt passed to $dateFromString / $dateFromParts all of them seem to be a too long path to get a performing result. I am keen on new ideas to get me out of a “thinking tunnel” an review with a different perspective.
Regards,
Michael
Refactoring $arrayElemAt and other operators into a function makes the pipeline little manageable. However, I’m not sure, if there is a way to get a substring once the delimiter count is met like you mentioned.
Here’s my attempt at the solution. There’s still plenty of room for improvement since I haven’t tested the performance aspect against millions of docs like mentioned in your use case.
Now, you cannot have multiple fields named value1 in your output document but you can populate them the same way by getting the appropriate element out of the array that results from $split expressions.
Hello @Asya_Kamsky
thanks for the starting point, I could work from there and currently optimize the resulting query since I had to cover some more surrounding conditions.
Until now I could not figure out why I get no ISODate back but a date object. I tried also with your example in an VS Playbook and got, surprisingly also a $date back.
"date": {
"$date": "2017-02-21T00:00:00Z"
}
I would like to get: "date" : ISODate("2017-01-27T00:00:00Z") }