mongoose-findorcreate icon indicating copy to clipboard operation
mongoose-findorcreate copied to clipboard

Why are the properties that contain the dollar sign eliminated?

Open econtigliani opened this issue 3 years ago • 1 comments

Hello, i have this question , in a part of index.js have:

// If the value contain '$' remove the key value pair
        var keys = Object.keys(conditions);

        for (var z = 0; z < keys.length; z++) {
          var value = JSON.stringify(conditions[keys[z]]);
          if (value && value.indexOf('$') !== -1) {
            delete conditions[keys[z]];
          }
        }

I need to save message = { text: "the price is $550"} and I can't, have any solution?

econtigliani avatar Apr 22 '22 22:04 econtigliani

This was added in pull #6. It looks like the intention was to omit any properties which are obviously non-data query operators. However, the implementation to do this incorrectly checks the values of properties instead of just the property names.

Since #6 was accepted to mongoose-findorcreate, it is now part of the API. The intention is to remove any keys beginning with $, so at least that behavior must be preserved. But I think fixing it to ignore values would be correct/accepted.

binki avatar May 07 '22 17:05 binki