Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
Altering immutable field _id error Mongo DB .net

I keep getting this error:

System.AggregateException: One or more errors occurred. (Command findAndModify failed: After applying the update, the (immutable) field ‘_id’ was found to have been altered to _id: BinData(3, 00000000000000000000000000000000).) —> MongoDB.Driver.MongoCommandException: Command findAndModify failed: After applying the update, the (immutable) field ‘_id’ was found to have been altered to _id: BinData(3, 00000000000000000000000000000000).

I'm not trying to change the _id I'm just filtering on id. The record/document I update the old document with don't have Id I just want to update all the other fields/keys.

The code:

public T UpsertRecord<T>(string table, Guid id, T record)

{
    var collection = db.GetCollection<T>(table);

    var filter = Builders<T>.Filter.Eq("_id", id);

    Task task = collection.FindOneAndReplaceAsync<T>(filter, record, new FindOneAndReplaceOptions<T, T> { IsUpsert = true });

    task.Wait();

    return record;


}

Below is the data im trying to post/update()responsePerson.Id:

  //Update data
    const string testNameUpdate = "MrSnail";
    const int testTotalUpdate = 2;
    var testPersonUpdate = new TestObj { name = testNameUpdate, total = testTotalUpdate };
    var responseUpdate = _mongoDBFeedClient.UpsertRecord(collectionName, responsePerson.Id, testPersonUpdate);

I have tried replaceone method and such.

I’m using Atlas Cloud Mongo DB and its “sharded”. I don’t know if it have anything to do with this but it might. I don’t wanna change the id just update all the rest of the values id the document exists if it doesn´t I wanna create it.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda