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

1.2K
Views
findOneAndUpdate, la devolución de llamada debe ser una función, obtuve [objeto Objeto], NodeJs, error de mangosta

Estoy desarrollando una aplicación web en la pila MERN, mientras lo hacía me encontré con un error, por favor ayuda. Cuando trato de actualizar el usuario, me da un error, la devolución de llamada debe ser una función, obtuve '[objeto Objeto]'.

Esta es la API.

Se garantiza que el usuario siempre existe.

 module.exports.addBlog=(req,res)=>{ const {title,data} = req.body.blog; console.log(title,data); const {email} = req.body; const newblog ={ title, data } userSchema.findOneAndUpdate( {email}, {$push:{blogArray:newblog}}, {upsert:true}, {useFindAndModify:false} ) .then(res=>console.log(res)) .catch(err=>console.log(err)); return res.json({msg:"Blog added successfully"}); }

Este es el esquema de usuario.

 const userSchema = new mongoose.Schema({ firstname:{ type:String, required:true, lowercase:true }, lastname:{ type:String, required:true, lowercase:true }, email:{ type:String, required:true, lowercase:true }, password:{ type:String, required:true }, blogArray:[ { title:{ type:String, required:true }, data:{ type:String, required:true } } ] });
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

findOneAndUpdate tiene 3 firmas posibles:

 findOneAndUpdate( filter: FilterQuery<TSchema>, update: UpdateQuery<TSchema> | TSchema, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>, ): void;
 findOneAndUpdate( filter: FilterQuery<TSchema>, update: UpdateQuery<TSchema> | TSchema, options?: FindOneAndUpdateOption<TSchema>, ): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
 findOneAndUpdate( filter: FilterQuery<TSchema>, update: UpdateQuery<TSchema> | TSchema, options: FindOneAndUpdateOption<TSchema>, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>, ): void;

Está tratando de usar la firma n. ° 2, la que utiliza una promesa, por lo que debe cambiar su sintaxis a:

 userSchema.findOneAndUpdate( {email}, {$push:{blogArray:newblog}}, {upsert:true, useFindAndModify:false}, ) .then(res=>console.log(res)) .catch(err=>console.log(err));

ver todos los tipos de nodos de Mongos aquí

over 4 years ago · Santiago Trujillo 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!