I'm creating an aplication with nodejs and mongodb and I have this:
var mongoose = require('mongoose');
var db = mongoose.connect("mongodb://localhost/dbTienda");
var esquemaUsuarios = new mongoose.Schema({
nombre: String,
apellido: String,
email: String,
contrasena: String,
notificaciones: Number,
notificacionesLista: [String],
articulos_vendidos: Number,
productos: [{
nombre: String,
imgPath: String,
precio: Number,
ciudades: [String],
tags: [String],
descripcion: String
}]
}), usuarios = db.model("Usuarios",esquemaUsuarios);
The problem is that I can't add anything in productos, the idea I have is to make some like this
productos: {
{nombre:XXXXX,imgepath:XXXXX,precio:XXXXX,ciudades:{ XXXXX },tags:{ XXXXX },descripcion: XXXXX},
{nombre:XXXXX,imgepath:XXXXX,precio:XXXXX,ciudades:{ XXXXX },tags:{ XXXXX },descripcion: XXXXX},
{nombre:XXXXX,imgepath:XXXXX,precio:XXXXX,ciudades:{ XXXXX },tags:{ XXXXX },descripcion: XXXXX},
{nombre:XXXXX,imgepath:XXXXX,precio:XXXXX,ciudades:{ XXXXX },tags:{ XXXXX },descripcion: XXXXX}
}
I want to add many objects for example first object is maybe a celphone second a tv ... etc. I can't add anything and I'm using this:
mongoose.model('Usuarios').update({
productos:[{$pushAll:{
nombre: informacion.pNombre,
imgPath: informacion.pImagen,
precio: informacion.pPrecio,
ciudades: informacion.pCiudades,
tags: informacion.pTags,
descripcion: informacion.pDescripcion
}},{upsert:true}]
});
but it doesn't work! I can edit nombre apellido email ... etc but I can't with productos.