[SERVER-8239] $concat should fail on non-string types Created: 18/Jan/13  Updated: 26/Aug/17  Resolved: 07/Feb/13

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 2.4.0-rc1

Type: Bug Priority: Major - P3
Reporter: James Wahlin Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to SERVER-30461 aggregation $concat expression is inc... Backlog
Operating System: ALL
Participants:

 Description   

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");



 Comments   
Comment by auto [ 07/Feb/13 ]

Author:

{u'date': u'2013-02-07T19:54:52Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: SERVER-8239 $concat should only support strings
Branch: master
https://github.com/mongodb/mongo/commit/c2ff9da39bcc046e1964c86eb9ce436b9f6efc9c

Comment by James Wahlin [ 25/Jan/13 ]

redbeard0531 - when do you expect to have code checked in for this ticket? I need to know whether I can hit a Feb 1st deadline for my test ticket.

Comment by Mathias Stearn [ 18/Jan/13 ]

That would mean that $concat is different from $add. With $add, any nullish value results in a null return. I'd think the same semantics would make sense for $concat.

Note that $concat is like $add (intra-document expression) not like $sum (cross-document accumulator).

Comment by Andy Schwerin [ 18/Jan/13 ]

I believe that null, undefined and missing are intended to be equivalent to empty string for $concat. Agree on the others, though.

Generated at Thu Feb 08 03:16:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.