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

364
Views
Obtención de error solo en mongoose, no en mongo Shell Error: no se puede usar $ o

Tengo una colección de blogs cuyo esquema es algo como a continuación

 { content:String, type:String, author:Number }

Consulta

 const edit = await Posts.findByIdAndUpdate( { _id: postId, $or: [ { type: "blog" }, { author: 123 }, ], }, { $set: { content:"...new" }, } );

Al ejecutar esto, recibo el siguiente error

 Error: Can't use $or at ObjectId.SchemaType.castForQuery (/home/rahul/Desktop/projects/components/components-server/node_modules/mongoose/lib/schematype.js:1539:13) at ObjectId.SchemaType.castForQueryWrapper (/home/rahul/Desktop/projects/components/components-server/node_modules/mongoose/lib/schematype.js:1511:22) at cast (/home/rahul/Desktop/projects/components/components-server/node_modules/mongoose/lib/cast.js:316:39) at model.Query.Query.cast (/home/rahul/Desktop/projects/components/components-server/node_modules/mongoose/lib/query.js:4963:12) at castQuery (/home/rahul/Desktop/projects/components/components-server/node_modules/mongoose/lib/query.js:4764:18) at model.Query.Query._findAndModify (/home/rahul/Desktop/projects/components/components-server/node_modules/mongoose/lib/query.js:3707:23) at model.Query.<anonymous> (/home/rahul/Desktop/projects/components/components-server/node_modules/mongoose/lib/query.js:3267:8) at model.Query._wrappedThunk [as _findOneAndUpdate] (/home/rahul/Desktop/projects/components/components-server/node_modules/mongoose/lib/helpers/query/wrapThunk.js:27:8)

Pero la misma consulta funciona con CLI mongo shell

 db.posts.findOneAndUpdate({_id:ObjectId("postId"),$or:[{type:"blog"},{author:123}]},{$set:{content:"blog78"}})
about 4 years ago · Juan Pablo Isaza
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!