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

182
Views
$in requiere una matriz como segundo argumento, encontrado:

cuando un usuario inicia sesión y hace clic en el botón del carrito, quiero ver los productos que agregó el usuario en mi consola. en mi colección de carritos hay algunos documentos que contienen ID de usuario e ID de productos. Por lo tanto, cuando un usuario hace clic en el enlace del carrito en la barra de navegación, quiero ver los productos que el usuario agregó al carrito en mi consola, pero en lugar de esto obtengo esto error.esta es la primera vez que uso agregado en monogodb

getCartProduct en usehelpers.js

 getCartProducts: userId => { return new Promise(async (resolve, reject) => { let CartItems = await db .get() .collection(Collection.CART_COLLECTIONS) .aggregate([ { $match: { user: objectId(userId) }, }, { $lookup: { from: Collection.PRODUCT_COLLECTIONS, let: { prodList:'$products' }, pipeline: [ { $match: { $expr: { $in: ['$_id', '$$prodList'], }, }, }, ], as: 'CartItems', }, }, ]) .toArray(); resolve(CartItems); }); }, };

argumentos pasados desde user.js

 router.get('/cart',verifyLogin,async(req,res)=>{ let products = await userHelpers.getCartProducts(req.session.user._id) console.log(products); res.render('user/cart') })

error de la consola

 MongoServerError: PlanExecutor error during aggregation :: caused by :: $in requires an array as a second argument, found: objectId at Connection.onMessage (C:\Users\krish\OneDrive\Desktop\project mern stack\webdev-challenge\node_modules\mongodb\lib\cmap\connection.js:210:30) at MessageStream.<anonymous> (C:\Users\krish\OneDrive\Desktop\project mern stack\webdev-challenge\node_modules\mongodb\lib\cmap\connection.js:63:60) at MessageStream.emit (events.js:400:28) at processIncomingData (C:\Users\krish\OneDrive\Desktop\project mern stack\webdev-challenge\node_modules\mongodb\lib\cmap\message_stream.js:132:20) at MessageStream._write (C:\Users\krish\OneDrive\Desktop\project mern stack\webdev-challenge\node_modules\mongodb\lib\cmap\message_stream.js:33:9) at writeOrBuffer (internal/streams/writable.js:358:12) at MessageStream.Writable.write (internal/streams/writable.js:303:10) at Socket.ondata (internal/streams/readable.js:731:22) at Socket.emit (events.js:400:28) at addChunk (internal/streams/readable.js:293:12)
about 4 years ago · Santiago Gelvez
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!