globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

mgo expression for `undefined` #211

Closed davisford closed 6 years ago

davisford commented 6 years ago

So, JS has null and undefined.

I am trying to do a projection like the following in mgo:

{ $project: {
    name { $cond: {
         if: { $eq: ['$foobar', undefined ] },
         then: '$foo',
         else: { $concat: [ '$foobar.name', '-', '$foo' ] },
    } },
}

But I cannot represent undefined in golang / bson.M parlance. The keyword nil does not work.

Any ideas?

davisford commented 6 years ago

Sorry, spoke too soon. I see there is a bson.Undefined constant that can be used.