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

143
Views
How to remove an nested array element from Array

I want to remove an nested array element if its first value is 0 from array. The data is shown below.

[
  {
    "data": [[0,1],[2,3],[0,3],[4,5]]
  }
]

test case

And here is my solution, which doesn't work.

db.collection.update({},
{
  "$pull": {
    "data": {
      "$elemMatch": {
        "0": 0
      }
    }
  }
})
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you're using Mongo version 4.2+ you can use pipelined updates like so:

db.collection.update({},
[
  {
    $set: {
      data: {
        $filter: {
          input: "$data",
          as: "datum",
          cond: {
            $ne: [
              {
                $arrayElemAt: [
                  "$$datum",
                  0
                ]
              },
              0
            ]
          }
        }
      }
    }
  }
])

Mongo Playground

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!