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

200
Visualizações
How to listen specific fields in mongodb database by changestream?

I have a collection on my mongodb database name users and every user contains a field name posts . I want to get realtime changes data of that posts field when a user add a new post or update existing post and take the updated value from socket server and send it back to frontend.

a single user documents looks like this

 [  
    {
        "_id" : "613fb31a52ef63541d036fcd",
        "posts"["613fb31a52ef63541d036fdf", "613fb31a52ef63541d036ff1"],
        "mobiles" : [ "01751150412"],
        "languages" : [ "English", "Bangla"],
     }
]

At first, I tried with const userChangeStream = connection.collection("users").watch()

that gives me all the fields of the user collection that wasn't even changed.

Then i followed this stackoverflow question and updated my code

 const filter = 
 [
   {
      $match: 
      {
        $and: 
        [
          { "updateDescription.updatedFields.posts": { $exists: true } },
          { operationType: "update" }
        ]
      }
   }
]

const options = { fullDocument: 'updateLookup' };

const postsChangeStream =    connection.collection("users").watch(filter,options);

postsChangeStream.on("change", (change) => {
  console.log('change on', change);
});

Now I dont get any response when adding on that posts field .

about 4 years ago · Juan Pablo Isaza
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