GUID Driver for C #

Having some problems returning requests from Mongo to Id when this is a guide. I have a really stupid test class, its just open Guid Id {get; set}. I create a collection and insert this test class. In the shell, I see it as

{ "_id" : BinData(3,"9q+FwoU/RE2+Iq3w7hK1JA==") } 

Then i try to do

 var query = Query.EQ("Id", Id); 

If I look in the debugger, it displays as

 { "Id" : CSUUID("c285aff6-3f85-4d44-be22-adf0ee12b524") } 

However, it does not return anything. Did I miss something obvious here? Also, note that the shell does not know what CSUUID is .. is there any way to enable this? CentOS server, if it is important ...

+4
source share
1 answer

Id will be automatically mapped to the name of the reserved primary key _id . You must change your request to

 Query.EQ("_id", Id) 

This should solve your problem.


Some GUID Information

However, this CSUUID thing is good to understand: it tells you that the driver uses an outdated GUID representation in the C # driver. I believe this is still defaulted, so no need to worry. There are different encodings, as other languages ​​or operating systems have different byte orders.

You can expand the shell to "understand" the various GUID formats, a very useful extension anyway for all kinds of debugging:

https://github.com/mongodb/mongo-csharp-driver/blob/master/uuidhelpers.js

This makes shell debugging easier. Just download js and run mongo using mongo --shell uuidhelpers.js .

+4
source

Source: https://habr.com/ru/post/1387093/


All Articles