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

$concat should fail on non-string types

    • ALL

      The following non-string types are allowed by the $concat operator. They should instead trigger an exception to be thrown:

      • Null
      • undefined
      • missing
      • Timestamps
      • Dates
      • Code

      The jstests used to verify this are:

      c = db.s6570;
      c.drop();
      c.save({s: BinData(0,"e8MEnzZoFyMmD7WSHdNrFJyEk8M=")
      		, t: ObjectId()
      		, u: /abc.*def/i
      		, v: null
      		, w: undefined
      		, x: new Timestamp()
      		, y: new Date()
      		, z: function() { var j=3; }  });
      
      assert.throws(function() {c.aggregate({$project:{_id:0, num : { $concat:[1, "$v", 2, "$v"] }}}).result;}, null, "$concat - null");
      assert.throws(function() {c.aggregate({$project:{_id:0, num : { $concat:[1, "$w", 2, "$w"] }}}).result;}, null, "$concat - undefined");
      assert.throws(function() {c.aggregate({$project:{_id:0, num : { $concat:[1, "$x", 2, "$x"] }}}).result;}, null, "$concat - timestamp");
      assert.throws(function() {c.aggregate({$project:{_id:0, num : { $concat:[1, "$y", 2, "$y"] }}}).result;}, null, "$concat - date");
      assert.throws(function() {c.aggregate({$project:{_id:0, num : { $concat:[1, "$z", 2, "$z"] }}}).result;}, null, "$concat - function");
      assert.throws(function() {c.aggregate({$project:{_id:0, num : { $concat:[1, "$missing", 2, "$missing"] }}}).result;}, null, "$concat - missing");
      

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            james.wahlin@mongodb.com James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: