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

134
Visualizações
Mongodb - watch changestream in documents with nested array element of certain value

Here is my document:

{
    "_id": {
        "$oid": "6257a55d04bf2167733f5b72"
    },
    "attributes": {
        "CustomerName": "John",
        "CustomerID": "28374",
        "LoanID": "82349327409234"
        "type": "Record",
        "Pointers": [
           {"type":"car","token_id":"123"},
           {"type":"house","token_id":"456"}
        ]
    }
}

Here is my watch query aiming to watch for Pointers elements with type:"car":

var watchCursor = db.loans.watch([
  {
    $match: {
      "$or": [
        {
          "updateDescription.updatedFields.attributes.Pointers": {
            $elemMatch: {
              "type": "car"
            }
          }
        },
        {
          "fullDocument.attributes.Pointers": {
            $elemMatch: {
              "type": "car"
            }
          }
        }
      ]
    }
  }
]);
while (!watchCursor.isExhausted()){
   if (watchCursor.hasNext()){
      print(JSON.stringify(watchCursor.next()));
   }
}

The problem is that I alter the document but it does not return any change results.

As a test, I changed the $elemMatch stage to $exists: true, then alter the document and it returned the changed document successfully.

what's wrong?!

about 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