[CSHARP-1889] Where clause comparison failure Created: 11/Jan/17 Updated: 27/Oct/23 Resolved: 11/Jan/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | API |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | John Fricker | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I'm trying to update our mongo driver from an older version to the 2.4 version, but I've hit a problem. Old code:
New code:
Using the new code returns the following error, whereas the old code worked: Additional information: Unsupported filter: ({plan.sstats.used} < {plan.sstats.available}). Is there anything I can do to resolve this and retain the atomic nature of the old operation? |
| Comments |
| Comment by Robert Stam [ 11/Jan/17 ] | ||||||
|
The 2.x filter builders do not have a helper method for creating "$where" filters. I imagine this is on purpose because we want to discourage use of $where. But if you still want to use "$where" in the 2.x API you can use a JsonFilterDefinition and pass it the "$where" expression directly like this:
Since strings can be converted to FilterDefinitions you could also write either of the following which both end up creating a JsonFilterDefinition:
| ||||||
| Comment by Robert Stam [ 11/Jan/17 ] | ||||||
|
Those are two different types of Where. The legacy API Query.Where translated into a "$where" query operator. "$where" is very expensive and normally not recommended. The second Where is a type-safe way of creating a filter to be used with Find and the error indicates that the given expression cannot be translated to the MongoDB query language (the reason is that the MongoDB query language only supports comparing a field to a constant, not comparing two fields). I'll have to investigate if there is a way to use "$where" with the 2.x filter builders. |