Hangfire is not working for CosmosDB after migrating from MongoDB giving error: A bulk write operation resulted in one or more errors. WriteErrors: [ { Category : "DuplicateKey", Code : 11000, Message : "E11000 duplicate key error collection: Hangfire

Murtuza Pithawala 0 Reputation points
2023-09-06T10:25:26.57+00:00

We were using MongoDb in our project and Hangfire was working perfectly fine over there but after we have shifted to CosmosDb Hangfire has stopped working, we are using MongoClient only to connect to CosmosDB by passing CosmosDB connection string to MongoClient everything is fine with this MongoClient object but Hangfire is not working with this. It is creating Hangfire default collections into the CosmosDB and when we are trying to manually execute any of the jobs from Hangfire dashboard it gives us this error:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]       An unhandled exception has occurred while executing the request. MongoDB.Driver.MongoBulkWriteException`1[MongoDB.Bson.BsonDocument]: A bulk write operation resulted in one or more errors. WriteErrors: [ { Category : "DuplicateKey", Code : 11000, Message : "E11000 duplicate key error collection: bomHangfire2.core.hangfire.jobGraph. Failed _id or unique index constraint." } ].    at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IClientSessionHandle session, IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)    at MongoDB.Driver.MongoCollectionImpl`1.<>c__DisplayClass30_0.
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,560 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,638 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Murtuza Pithawala 0 Reputation points
    2023-10-05T09:12:31.4733333+00:00

    This issue is closed Hangfire has fixed this issue. Thank you.


  2. Oury Ba-MSFT 19,101 Reputation points Microsoft Employee
    2023-10-06T15:39:02.79+00:00

    @Murtuza Pithawala Thank you for reaching out.

    Problem:

    Hangfire is not working for CosmosDB after migrating from MongoDB giving error: A bulk write operation resulted in one or more errors. WriteErrors: [ { Category : "DuplicateKey", Code : 11000, Message : "E11000 duplicate key error collection: Hangfire

    Solution:

    Customer contacted Hangfire who fixed the issue.

    Regards,

    Oury

    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.