I posted a question yesterday - that, because if not knowing "how" to ask, it was poorly presented - So if you recognize the structure/data, please re-read, I hope I am able to present it in a clearer manner.
I want to return an array of items from multiple nested arrays of objects.
My ultimate goal is something that look like this...
{person:1, cost: ['23,543','56,556','8,500']},
{person:2, cost: []}
This lets me know 2 pieces of information, 1- it allows me to total across two or more arrays of objects, and 2- it lets me see persons who have NOT filled in information.
The Scenario:
I have a couple array of objects, and I want to find out if people are filling in 'cost' on an object.
So a model that looks like this.
person : {
my_cars: [
{
make:
model:
cost:
}
],
my_motorcycles: [
{
make:
model:
cost:
}
]
}
Some data will look like this (and this data corresponds to my above desired result...)
person : {
_id: 1
,my_cars: [
{
make: 'ford'
model: 'taurus'
cost: null
},
{
make: 'ford'
model: 'mustang'
cost:'23,543'
}
,{
make: 'lincoln'
model: 'navigator'
cost: '56,556'
}
]
,my_motorcycles: [
{
make: 'ducati'
model: ''
cost: '8,500'
}
,{
make: 'yamaha'
model: 'v-star 650'
cost: ''
}
]
}
,person : {
_id: 2
,my_cars: [
{
make: 'ford'
model: 'taurus'
cost: null
},
,{
make: 'chevy'
model: 'chevette'
cost: null
}
]
,my_motorcycles: [
{
make: 'harley-davidson'
model: 'softtail'
cost: ''
}
,{
make: 'honda'
model: 'x650'
cost: ''
}
]
}
So what I am trying to do is unwind but if I try
$unwind{
path: "$my_cars.cost"
}
,$unwind{
path: "$my_motorcycles.cost"
}
this is not working...
Any help on getting to an output close to knowing the Number of an instance of a field in multiple nested arrays is greatly appreciated