简体   繁体   中英

Is there a nuget package to convert a json filter to Lambda expression? - MongoDB Driver

I was wondering if there is any nuget package that converts a string, let's say like the following:

"{ name: 'Carlos' }"

to a Lambda Expression.

I'm not talking about doing a manual conversion, but more about doing it dynamically. The reason is because I have a REST API that allows the user to send the filter property in a query param and in this it can send something similar to the string above as a value so that client apps can apply filters to obtain certain documents.

The logic to make these conversions is somewhat complicated, because you have to evaluate the possible comparisons that the client makes, so I was wondering if there is already a solution.

I use MongoDB.

mongodb driver itself can take in a json string for the filter like so:

var filter = "{ name: 'Carlos' }";

var result = await collection.Find(filter).ToListAsync();

it works because of the implicit operator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM