I use nodejs, mongoose odm and mongo for a web application, and I am encountering problems trying to run a group by style request in mongoose:
var results = mymodel.collection.group ( { keyf: function(doc) { var m = doc.date.getMonth(); var d = doc.date.getDate(); var y = doc.date.getFullYear(); return { date: m + "/" + d + "/" + y }; }, cond: {}, reduce: function(doc,prev) { prev.total += doc.value; }, initial: { total: 0 } } ); if(results == null) { console.log("results is null\n"); }
if I run the code "mymodel.collection.group" in the mongo shell, it works fine. However, nodejs / mongoose seems to return a null result, although the mongoose documentation states that direct mango code can be run against the mongo native driver.
Does anyone have any ideas how to solve them?
source share