[CSHARP-4139] Unsupported filter x => x.SiteId.ToString().ToLower().Contains("634bb6fc") Created: 15/Apr/22 Updated: 27/Oct/23 Resolved: 05/May/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | LINQ3 |
| Affects Version/s: | 2.15.0 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Unknown |
| Reporter: | chock chen | Assignee: | Boris Dogadov |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Description |
|
Hi, I tried to retrieve using the expression and was prompted that it was not supported. NOTE: The SiteId here is type of Guid Following is my information: |
| Comments |
| Comment by chock chen [ 05/May/22 ] | |||||
|
Thank you so much | |||||
| Comment by Boris Dogadov [ 02/May/22 ] | |||||
|
Hi chock-cong.chen@outlook.com For serializing GUID as a string you can use the following BSON attribute:
And then x => x.Field.ToString().Containts(...) should work. To learn more about serialization please see the serialization guide.
| |||||
| Comment by chock chen [ 25/Apr/22 ] | |||||
|
Hi, boris.dogadov@mongodb.com. Expression<Func<Equipment, bool>> predicate = x => JsonConvert.SerializeObject(x.SiteId).Contains("89f456d9"); So about the above expression, could you provide an applicable solution. | |||||
| Comment by Boris Dogadov [ 19/Apr/22 ] | |||||
|
Thank you for your question, This behavior is expected. The problem is that by default GUIDs are stored as BinData, while $toString is not defined for BinData types. Matching a substring would require serializing GUID as a string. Matching the whole GUID field can be done directly:
|