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

428
Views
Mongodb 4.4.x - findOneAndUpdate() con $set y $push

Estoy tratando de hacer findOneAndUpdate() para encontrar un documento y actualizarlo en una operación atómica

 db.characters.insertOne({ movies: ['Star Trek'], name: 'Jean-Luc Picard' }) db.characters.findOneAndUpdate({ name: 'Jean-Luc Picard' }, [ { $set: { age: 59 } }, { $push: { movies: 'Next Gen' } } ])

da error

 uncaught exception: Error: findAndModifyFailed failed: { "ok" : 0, "errmsg" : "Unrecognized pipeline stage name: '$push'", "code" : 40324, "codeName" : "Location40324" } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:742:15 DBCollection.prototype.findOneAndUpdate@src/mongo/shell/crud_api.js:910:12 @(shell):1:1

¿Existe una sintaxis diferente para insertar un elemento en una matriz? También probé $addToSet que tampoco funcionó.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Prueba esto, probablemente funcionará:

 db.characters.findOneAndUpdate({ name: 'Jean-Luc Picard' }, { $set: { age: 59 }, $push: { movies: 'Next Gen' } })
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!