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

133
Vistas
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 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