[DOCS-1152] Unclear how to use $cond and $ifnull aggregation operators Created: 22/Feb/13  Updated: 26/Sep/13  Resolved: 25/Sep/13

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Daniel Gottlieb (Inactive) Assignee: Zack Brown
Resolution: Done Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 10 years, 20 weeks, 6 days ago

 Description   

http://docs.mongodb.org/manual/reference/aggregation/#conditional-expressions

The documentation refers to "boolean-expression", "true-case", "false-case" for $cond and "expression", "replacement-if-null" for $ifNull.

Are these types strings that contain javascript expressions? Are document elements usable as inputs? If documents being aggregated on are not available, what can this be used for? A non-trivial example usage would definitely go a long way.



 Comments   
Comment by auto [ 26/Sep/13 ]

Author:

{u'username': u'Zackrobat', u'name': u'Zack Brown', u'email': u'zack.brown@10gen.com'}

Message: DOCS-1152: Unclear how to use and aggregation operators

Signed-off-by: Sam Kleinman <samk@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/1fbd54c356c7aa17091d1ece18800c23e6739b7b

Comment by Jochen Kemnade [ 24/Jul/13 ]

I'm currently trying to combine $cond with $project. I want to transform non-array values into arrays, so my expression looks something like

 
  {"$cond": [ Array.isArray("$value"), "$value", ["$value"] ] }

From my experiments, I can tell that boolean-expression, true-case and false-case are actual expressions, not strings:

  {"$cond": [ true, 1, 2 ] }

works like one would expect.
The question that remains is how to use values from the documents; expressions like "$value" are treated as regular strings and this is apparently an empty object.

Generated at Thu Feb 08 07:40:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.