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

275
Views
MongoDB query to remove a key of an Object in my database

So, basically I'm trying to make an API Restful (just for studies purposes) with:

NodeJS, Express and MongoDB

I already have my database set up, but I need to delete a Key from an Object.

If I send a request GET in my messages endpoint, this will return:

[
    {
        "_id": "5f9b1e0186a911001714dd3c",
        "texto": "será se vai ?"
    },
    {
        "_id": "604fd3859b2fd50017027472",
        "texto": "salve rapaziada esse aqui é o texto que eu to colocando"
    },
    {
        "_id": "604fd4389b2fd50017027474",
        "texto": "Mensagem editada aAa",
        "mensagem": ""
    }
]

The text is in PT-BR

The key mensagem was a misstake, but now I wanna know how to resolve.

So, I wanna delete mensagem key, the third object.

I'm using NoSqlBooster, but if someone use Mongo Compass, I need to know too.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

$unset

update

unset will remove the key from the collection and passing true at the end of the update method is a flag set to `update multiple records.

db.collectionName.update({}, { $unset: { mensagem:1 } }, { multi: true });
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!