Created
November 25, 2015 22:11
-
-
Save alexshyba/51cd43df21455cf7205a to your computer and use it in GitHub Desktop.
Mongo: accessing goal properties in XDB with map reduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map = function m() { | |
for (var p = 0; p < this.Pages.length; p++) | |
{ | |
if(this.Pages[p].PageEvents){ | |
for (var e = 0; e < this.Pages[p].PageEvents.length; e++){ | |
var key = this.Pages[p].PageEvents[e].Name; | |
var text = this.Pages[p].PageEvents[e].Text; | |
if(text && text.indexOf('=' > -1) && text.indexOf('&' > -1)){ | |
var keys = text.split("&"); | |
if(keys.length > 0) | |
{ | |
var valueIndex = 1; | |
if(keys[valueIndex]){ | |
var value = keys[valueIndex].split("=")[1]; | |
if(value > 0) | |
emit(key, +value); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
var reduce = function r(id,docs) { | |
return Array.sum(docs); | |
} | |
db.Interactions.mapReduce(map,reduce,{query: { StartDateTime: { | |
$gte: ISODate("2014-10-01T00:00:00.000Z"), | |
$lt: ISODate("2015-12-17T00:00:00.000Z")}}, | |
out:"orders"}); | |
db.orders.find() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment