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

172
Views
Moongose: update record pushing element into array

Sorry for my poor english, I hope you understand what I mean.

I have a mongoDb database with many tables. In my table "Files" all the records has a field called "etiquetas". This field is an array of strings. I want to update this field (in a the record with id XXXX) inserting new strings. I have read the docs of mongoose and I have tried to update a record using "push" function, but mongoose its inserting an object and not a string into the array "etiquetas".

Let me show you whats is happening. This is whats Im doing to update the record (in a nodejs app):

let exampleString = "61c43b346c6168d039f8c0gg"; // Using an example string
await File.updateOne(
  { id: fileId },
  { $push: { etiquetas: { exampleString } } }
);

And this is what is happening (I have inserted manually the first record of the array "etiquetas"):

click to see what it happens

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

0

Try to remove the curly braces surrounding the exampleString:

let exampleString = "61c43b346c6168d039f8c0gg"; // Using an example string
await File.updateOne(
  { id: fileId },
  { $push: { etiquetas: exampleString } }
);
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!