im trying to push information in one array from my DB in mongo. But the information i want to save have another array.
My model:
var hotelSchema = new Schema({
version: Number,
name: String,
services: [{
name: String,
price: Number,
description: String,
images:[{
url: String,
md5: String,
ext: String
}],
subservices:[{
name: String,
price: Number
}]
}]});
Now, i want to add a Service, and this the way i use:
var u=req.body;
var subServices= [];
for(var i=0;i<u.nameSub.length;i++)
{
subServices.push({nombre: u.nameSub[i], precio: u.priceSub[i]});
}
Hotel.update({ "_id": doc._id},
{$push: {services:
{
name: u.name,
price: u.price,
description: u.desc,
subservices:subServices
}}}, function(err, result){ });
MongoDB save thats query but in subservices only save "_id". The result is (in this case i want to add 3 subservices):
{
"name" : "service",
"price" : 10,
"description" : "service test",
"_id" : ObjectId("542c64c0dd8de1340515c43f"),
"subservices" : [{
"_id" : ObjectId("542c64c0dd8de1340515c442")
},
{
"_id" : ObjectId("542c64c0dd8de1340515c441")
},
{
"_id" : ObjectId("542c64c0dd8de1340515c440")
}],
"images" : []
}
I need help. Anybody knows how i can do?
PD: Sorry for my bad English