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

104
Views
Returned object with nested values that comply condition with Mongoose

I'm querying an object from a collection that has a key with an array of objects. I want it to return the object and exclude the elements in the array that have "available: false".

Ex:

{
  name: "Willy's Store",
  city: "Baigorria",
  storeId:"666",
  open: [
    {day: monday, available: true}, 
    {day: tuesday, available:true}, 
    {day:wensday, available: true},
    {day:thursday, available:false}, 
    {day:friday, available:false}
  ]
}

on the query, the expected result should be

{
  name: "Willy's Store",
  city: "Baigorria",
  storeId:"666",
  open: [
    {day: monday, available: true}, 
    {day: tuesday, available:true}, 
    {day:wensday, available: true}
  ]
}

I want to only use mongoose to achieve it

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

0

You can use filter concept of arrays on open object to filter out available days.

    var data = {
    "name": "Willy's Store",
    "open": [{
        "day": "monday",
        available: true
    }, {
        "day": "tuesday",
        available: true
    }, {
        "day": "wensday",
        available: true
    }, {
        "day": "thursday",
        available: false
    }, {
        "day": "friday",
        available: false
    }]
}
data.open = data.open.filter(subData => subData.available)
console.log(data)

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!