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

is this a bug in $cond in $project, or am i using it wrong?

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.9
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL
    • Hide

      see above...

      Show
      see above...

      here's some data:

      > db.scratch.find()
      { "_id" : ObjectId("57e0bac25e54b80da88af731"), "a" : "baz" }
      { "_id" : ObjectId("57e0bac75e54b80da88af732"), "a" : "foo", "b" : "bar" }
      

      here's a pipeline, desired effect is to concat a and b if i have both fields, or just use a if b isn't present:

      > db.scratch.aggregate([{$project: {ab: {$cond: [{$eq: ['$b', null]}, '$a', {$concat: ['$a', ':', '$b']}]}}}])
      { "_id" : ObjectId("57e0bac25e54b80da88af731"), "ab" : null }
      { "_id" : ObjectId("57e0bac75e54b80da88af732"), "ab" : "foo:bar" }
      

      but when b is not present and i want a i get null... ?!

            Assignee:
            Unassigned Unassigned
            Reporter:
            tony-kerz tony kerz
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: