Having some issues querying back from Mongo on Id when it’s a guid. I have a really stupid test class, its just public Guid Id {get;set}. I create a collection and do an insert of this test class. In the shell i see it as
{ "_id" : BinData(3,"9q+FwoU/RE2+Iq3w7hK1JA==") }
I then try to do
var query = Query.EQ("Id", Id);
If I look in the debugger, it shows up as
{ "Id" : CSUUID("c285aff6-3f85-4d44-be22-adf0ee12b524") }
However, it doesn’t return anything.. Am I missing something obvious here? Also, side note, the shell has no idea what CSUUID is.. is there a way to enable this? CentOS server if it matters…
Idwill automatically be mapped to the reserved primary key name_id. You should change your query toThis should fix your problem.
Some Background about GUIDs
That thing about
CSUUIDis good to know, however: it tells you the driver is using the legacy representation of GUIDs in the C# driver. I believe this is still the default, so no need to worry. There are different encodings because other languages or operating systems have different byte orders.You can extend the shell to ‘understand’ different formats of GUIDs, a very helpful extension in any case for all kinds of debugging:
https://github.com/mongodb/mongo-csharp-driver/blob/master/uuidhelpers.js
This makes it easier to debug using the shell. Just download the js and start mongo using
mongo --shell uuidhelpers.js.