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

544
Visualizações
Remove a Guid(uuid) from a nested list via Mongo DB C# Driver

I have a MongoDB Model which consists of an Id(Guid) and a list of Ids (which are also Guids). Now... for some reason I want to query the list of UserIds and if there is an element with a certain Guid I want to remove it from my Mongo Array.

So here's a part of my model:

public class Model {
        [BsonId]
        [BsonRepresentation(BsonType.String)]
        public Guid Id { get; set; }

        [BsonElement("userIds")]
        public List<Guid> UserIds{ get; set; }
}

and here's the piece of code from the repository where the list of Guids should get an element removed.

var filter = Builders<Models.Event>.Filter.Eq(m => m.Id, someId);
var update = Builders<Models.Event>.Update.PullFilter(m => m.UserIds,
                                                i => i == userId);

await _events.FindOneAndUpdateAsync(filter, update);

In theory, this should work... The problem is Mongo keeps giving me the following error:

"error": "{document} is not supported.",

For some reason, my PullFilter doesn't seem to be able to identify my Guid in the DB.

Here's how the Guid is stored in the DB:

userIds:Array
0:Binary('WYsLZis0RkOeiQ1RNyjzGw==', 3)

Is this a conversion issue? Should I use a string instead of a Guid here? I can't figure out exactly what's happening behind the scenes and why this wouldn't work.

I also tried altering the code to have the Guid be converted to string and check the value against my userId.ToString() but then, i get {document}.ToString() is not supported.

Has anyone encountered this before?

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