Domanda

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.

È stato utile?

Soluzione 2

This was an error in my part. It looks like the Guid that was being returned back was not in the correct format in the viewer I was using. Robomongo likes to default to something they call a LegacyUUID however this is not the same format as the .Net Guid. I needed to change the options in the viewer make it display the correct Guid for me to look for.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top