Cannot deserialize a 'Guid' from BsonType 'ObjectId' in azure cosmos documentdb

95132786 2 Reputation points
2024-07-02T08:47:59.98+00:00

I am using Azure mongo db collection and accessing it via dotnet application. I am getting error for some of the documents "Cannot deserialize a 'Guid' from BsonType 'ObjectId'" while retrieving. In dotnet, model class having Id property of type guid and In document db, _id is stored as binary format. Mongo db version which we are using is MongoDB.Driver-"2.27.0". I am trying to access documents via findasync method and filtering using key property. Can you please help me to get out of this issue?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,906 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SSingh-MSFT 16,371 Reputation points Moderator
    2024-07-02T10:22:17.9533333+00:00

    Hi 95132786 •,

    Welcome to Microsoft Q&A forum.

    As I understand, you Cannot deserialize a 'Guid' from BsonType 'ObjectId' in azure cosmos documentdb via dotnet application.

    Please refer to the below posts with similar error if that helps:

    https://stackoverflow.com/questions/65402783/formatexception-cannot-deserialize-a-guid-from-bsontype-objectid

    https://www.mongodb.com/community/forums/t/cannot-deserialize-a-list-string-from-bsontype-string/222464

    Let us know if this helped, if not, please share configuration details of your database and sample dotnet code so that we can further look.

    Thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.