Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB C# driver: Using Linq to get Guid returns nothing

The following is the code I am using to query the database. The variable "filter" is a linq expression. It seems that I can use this code to get data using ObjectId or any other value that may be in the document. But when I store a Guid and try to retrieve it, there is no return. Is there something I am doing wrong here, or is there a limitation on MongoDB itself when it comes to Guids?

        _dbSet = mongoDatabase.GetCollection(collectionName);
        var query = _dbSet.AsQueryable<TEntity>();

        if (filter != null)
        {
            query = query.Where(filter);
        }

        return query.ToList();

EDIT:

Just to clarify a bit more. I have tried the solution shown here in the last comment: MongoDB and Guid in Linq Where clause. That does not give me a result either. The data I am trying to retrieve contains just the _id field.

{
    "_id" : LUUID("e5bdda3b-ae6a-d942-bd43-c8c7a6803096")
}

The entity being used to retrieve this object has only a property called Id which, from what I understand, translates to the _id field in the Mongo document. So I tried retrieving on the Id property as well. Still no result.

like image 440
jjkim Avatar asked Mar 20 '23 19:03

jjkim


1 Answers

Extending @jjkim's answer as I could not post image in comment:

You need to change the preference which comes under "Edit > Preferences" in Studio 3T for MongoDB.

enter image description here

like image 87
Sunny Sharma Avatar answered Mar 22 '23 18:03

Sunny Sharma