MongoDB and undefined values

Hey guys,
I’m having a little issue with MongoDB and a query with a undefined field. For example, we use this query:

let oldTransaction = Transaction.findOne({transactionApiId:this.transactionApiId,transactionId, requestId});

In some cases, transactionId is undefined. The problem is, that this query returns a document that has a defined transactionId value. So the query gets changed to:

let oldTransaction = Transaction.findOne({transactionApiId:this.transactionApiId, requestId});

It ignores the transactionId field completely. Is this the normal behavior? In the console, the query can’t be executed due to

"errmsg" : "cannot compare to undefined",

Mongoose converts all undefined values to null values. But Meteor seems to remove the fields. Thats some behavior I didn’t expect.

A couple of things:

  1. any command issued on the client gets converted to an EJSON string. Part of that process removes any key where the value is undefined so {key: undefined} -> {}
  2. In Mongo, you can use {key: {$exists: false}} which will allow you to find entries that have undefined values, rather than excluding the key.
  3. You may want to look here though the undefined type is deprecated