-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Shell
-
None
-
Environment:OS X 10.5
-
Fully Compatible
If I'm not misstaken diff should be accessible within the keyf function, due to closures. However, I need to place it within the keyf function for the shell to recognise it. Is this a bug perhaps?
Result without diff within the keyf function:
------------------------------------------------------------------------------------------------
> getThanks('summaries', "759df69a-589e-41a2-b316-a6c91a6fe975")
Sun Jul 12 17:40:24 JS Error: uncaught exception:
Result with diff within the keyf function:
------------------------------------------------------------------------------------------------
> getThanks('summaries', "759df69a-589e-41a2-b316-a6c91a6fe975")
[
,
{"day" : 1 , "month" : 5 , "year" : 2009 , "count" : 0},
{"day" : 26 , "month" : 5 , "year" : 2009 , "count" : 0}]
FUNCTION
------------------------------------------------------------------------------------------------
function getThanks(collection, id) {
var now = new Date();
var diff = 1000 * 60 * 60 * 24 * 30; // inaccessible
var res = db.group({
ns: collection,
// key:
,
keyf: function(a) {
var date = a.createdAt;
var time = date.getTime();
var now = new Date();
var diff = 1000 * 60 * 60 * 24 * 30; // accessible
// if (now.getTime() - time > diff)
return
{ "day":date.getDate(), "month":date.getMonth(), "year":date.getFullYear() };
},
initial:
,
reduce: function(obj, prev)
,
cond:
,
});
// group() returns an array of grouped items. here, there will be a single
// item, as key is {}.
return res;
}