Potential issue with MongoId fields
Hi there, there seems to be an issue with fields prefixed with an "_" such as the _id as field, when I run:
const filter = buildMongoConditionsFromFilters({},{ _id: "5c3fa5a6c0db55422042e379", });
it results in:
"id" is not a valid operator on field "".
at handleFieldOperator ./node_modules/@entria/graphql-mongo-helpers/dist/buildMongoConditionsFromFilters.js:39
at Object.keys.reduce ./node_modules/@entria/graphql-mongo-helpers/dist/buildMongoConditionsFromFilters.js:84
at buildConditionsObject ./node_modules/@entria/graphql-mongo-helpers/dist/buildMongoConditionsFromFilters.js:60
at buildMongoConditionsFromFilters ./node_modules/@entria/graphql-mongo-helpers/dist/buildMongoConditionsFromFilters.js:120
at Object.
This seems to stem from support from the way Mongo operators are handled. Fields are split on '_' to derive the operators. Since "id".split('') results in ['',id], "id" is assumed to be the operator and it causes to fail the valid operator test. This would also affect came cased fields but i saw from the comments that they are not supported.
Of course, i could be misreading the whole thing :) If not let me know if you would be interested in a pulll request. I am thinking easy way to solve it was thinking of adding another if statement to buildCondtionsObject to handle fields that start with "_". I also see a way to solve this and add support for camel casing without affecting backwards compatibility, but it would be larger refactor. Let me know your thoughts.
can you add a failing test?
the same problem occurred to me some time ago, I don't remember how I solved it.