Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Encuentra registro en mongo $nin en matriz

Tengo una base de datos (mongo) que almacena publicaciones y usuarios por separado. Dentro del esquema de publicaciones tengo una matriz. Cuando un usuario marca una publicación como leída, su identificación de usuario se inserta en la matriz en el esquema de la publicación. Luego intento mostrar solo las publicaciones cuya identificación de usuario no aparece en la matriz.

Aquí hay un ejemplo de la estructura de mi publicación.

 { "_id" : ObjectId("620eb60406b710c3ba2250f1"), "icon" : "fas fa-bullhorn", "title" : "Test Post", "scope" : true, "postedby" : "System", "postbody" : "Testing only content", "postcolour" : "orange", "posteddate" : "17/02/2022", "posthideuser" : [ "6205612355b2676a978b172b", "6203e917055a3558ffeb9fca" ] "__v" : 0 }

Intenté usar lo siguiente:

 const posts = await Post.find({ posthideuser: { $nin: [user_id] } });

Lo cual no ha funcionado.

Mi aplicación es nodo, express/ejs. Estaré encantado de proporcionar más información si es necesario. ¡Gracias por adelantado!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Su consulta parece funcionar como se esperaba:

 db.collection.find({ posthideuser: { $nin: [ "test2" ] } })

patio de juegos

about 4 years ago · Juan Pablo Isaza Report

0

Hubo un problema con la estructura como se indica.

 await Post.findByIdAndUpdate(id, { $push: { posthideuser: [res.locals.user_id] } });

debería ser: await Post.findByIdAndUpdate(id, { $push: { posthideuser: res.locals.user_id } });

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!