Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-13662

Date returned from group command initial object results in error

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.10, 2.6.0
    • Component/s: JavaScript, MapReduce
    • None
    • Query
    • ALL
    • Hide

      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()}
      });
      
      Show
      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()} });

      When running a group query where one of the properties of the Object passed as the initial aggregation result is a Date and that property is returned unmodified, the following error occurs:

      TypeError: Property 'getUTCFullYear' of object [object Object] is not a function

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            kevinoid Kevin Locke
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: