Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

327
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda