I store our web server logs in MongoDB , and the diagram looks something like this:
[ { "_id" : 12345, "url" : "http://www.mydomain.com/xyz/abc.html", .... }, .... ]
I am trying to use the $project operator to slightly change the shape of this schema before I start passing my collection along the aggregation pipeline. Basically, I need to add a new field called "type", which will later be used to perform group operations. The logic for the new field is pretty simple.
if "url" contains "pattern_A" then set "type" = "sales lead"; else if "url" contains "pattern_B" then set "type" = "existing client"; ...
I think it should be something like this:
db.weblog.aggregate( { $project : { type : { } } } );
I know how to do this using map-reduce (by setting the "keyf" attribute in a custom JS function that implements the above logic), but now I'm trying to use a new aggregation structure . I tried to implement the logic using expression operators, but still could not get it to work. Any help / suggestion would be greatly appreciated!
source share