1

I am using react-querybuilder in my project and recently using valueProcessor to change the value of field. The generated query result for SQL is OK but for MongoDb is not correct.

To simulate please visit this. I expect the following result :

{"$and":[{"firstName":{"$regex":"^jon"}},{"lastName":{"$in":["Vai","Vaughan"]}}]}

but this is the generated result:

{"$and":[jon,('Vai', 'Vaughan')]}

I wonder if I made a mistake or a bug.

Update : the link for simulation was broken now I fixed it.

2
  • Can you add the full query object you're passing to formatQuery? Commented Dec 21, 2022 at 14:10
  • @JakeBoone I made an update to this question. Thank you. Commented Dec 24, 2022 at 5:43

1 Answer 1

1

The CAUTION note about valueProcessors in the Export documentation explains why this is happening:

When producing non-SQL query language formats—including "mongodb", "cel", "spel", and "jsonlogic"—valueProcessor functions must produce the entire rule object (for MongoDB/JsonLogic) or rule string (for CEL/SpEL), not just the expression on the right-hand side of the operator like with SQL-based formats.

This situation exists for backwards-compatibility reasons, but to increase the clarity of your own code we recommend using the ruleProcessor option which has the same interface and effect as valueProcessor for all non-SQL query language formats.

You must produce the entire rule, but your valueProcessor is only returning “jon” when the field is “firstName”.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.