Let's say this is my MongoDB schema:
var shopSchema = new mongoose.Schema({
nameShop: String,
products: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Product'
}]
});
var productSchema = new mongoose.Schema({
nameProduct: String,
fruits: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Fruit'
}
]
});
var fruitSchema = new mongoose.Schema({
nameFruit: String,
price: Number
});
module.exports = {
Shop: mongoose.model('Shop', shopSchema),
Product: mongoose.model('Product', productSchema),
Fruit: mongoose.model('Fruit', fruitSchema)
}
I know that I can get data in this way, but result of that code is an "ugly" array
var Schema = require('../model/schema');
Schema.Shop.find({}).populate({
path: 'products',
model: 'Product',
populate: {
path: 'fruits',
model: 'Fruit'
}
}).exec(callback);
Is it possible to get data from this schema in way that I will have nice array? E.g.:
var MyArray = [
{ nameShop: "Tesco", nameProduct: "New", nameFruit: "Apple", price: 10 },
{ nameShop: "Tesco", nameProduct: "New", nameFruit: "Pinapple", price: 4 },
{ nameShop: "Eko", nameProduct: "Old", nameFruit: "Kiwi", price: 8 },
{ nameShop: "Makro", nameProduct: "Fresh", nameFruit: "Pear", price: 7 },
{ nameShop: "Carefour", nameProduct: "New", nameFruit: "Orange", price: 6 }
];
