| Steps To Reproduce: |
Modifying the example from the documentation by adding the field d with a Date value to the initial object, starting with a fresh database:
db.orders.insert({
|
_id: ObjectId("5085a95c8fada716c89d0021"),
|
ord_dt: ISODate("2012-07-01T04:00:00Z"),
|
ship_dt: ISODate("2012-07-02T04:00:00Z"),
|
item: { sku: "abc123",
|
price: 1.99,
|
uom: "pcs",
|
qty: 25 }
|
});
|
// Next command will cause an error
|
db.orders.group({
|
key: { ord_dt: 1, 'item.sku': 1 },
|
cond: { ord_dt: { $gt: new Date( '01/01/2012' ) } },
|
reduce: function ( curr, result ) { },
|
initial: {d: new Date()}
|
});
|
Either removing the property in the finalize function or overwriting it avoids the issue:
// Next command runs without error
|
db.orders.group({
|
key: { ord_dt: 1, 'item.sku': 1 },
|
cond: { ord_dt: { $gt: new Date( '01/01/2012' ) } },
|
reduce: function ( curr, result ) { },
|
initial: {d: new Date()},
|
finalize: function(result) { delete result.d; }
|
});
|
// As does this one
|
db.orders.group({
|
key: { ord_dt: 1, 'item.sku': 1 },
|
cond: { ord_dt: { $gt: new Date( '01/01/2012' ) } },
|
reduce: function ( curr, result ) { result.d = new Date() },
|
initial: {d: new Date()}
|
});
|
|