I am working with MongoDB
and made this a%% share% correctly with and I get this result:
{
"ok": true,
"mensaje": "Petición realizada correctamente",
"folios": [
{
"folioLineas": [
{
"nivelDeUrgencia": "URGENTE",
"almacen": true,
"_id": "5b6b1ec0b34c1b0e3cc010e9",
"folio": "5b6b147ab34c1b0e3cc010e0",
"modeloCompleto": {
"_id": "5b6b1e79b34c1b0e3cc010e8",
"modelo": "5b6b0e6bb34c1b0e3cc010de",
"tamano": "5b6b1e5eb34c1b0e3cc010e1",
"color": "5b6b1e5eb34c1b0e3cc010e2",
"terminado": "5b6b1e5eb34c1b0e3cc010e3",
"marcaLaser": "5b6b1e79b34c1b0e3cc010e7",
"versionModelo": "5b6b1e5eb34c1b0e3cc010e4",
"__v": 0
},
"cantidad": 18300,
"marcaLaser": {
"_id": "5b6b1e79b34c1b0e3cc010e7",
"marcaLaser": "ESTA ES LA MARCA LASER",
"__v": 0
},
"__v": 0
}
],
}
After I try to popular my GET
with this code:
//... Todo el get
.populate({
path: 'folioLineas',
populate: {
path: 'modeloCompleto marcaLaser',
populate: {
path: 'marcaLaser'
}
}
})
//... Más código.
But Mongo returns the following error:
{
"ok": false,
"mensaje": "Error cargando folios.",
"errors": {
"message": "Cast to ObjectId failed for value \"ESTA ES LA MARCA LASER\" at path \"_id\" for model \"MarcaLaser\"",
"name": "CastError",
"stringValue": "\"ESTA ES LA MARCA LASER\"",
"kind": "ObjectId",
"value": "ESTA ES LA MARCA LASER",
"path": "_id"
}
}
If I remove the last _id
the code works, but that last field path: 'marcaLaser'
I want it popular. How to avoid this behavior ?, or What could be doing wrong what mongoose tries to fill the field marcaLaser
with the text of _id
?
This is the marcaLaser
model:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var uniqueValidator = require('mongoose-unique-validator');
var marcaLaserSchema = new Schema({
laser: { type: String, unique: true },
imagen: { type: String },
// Esto de aqui es para que mongose no escriba
// marcaLasers en vez de marcaLaseres
}, { collection: 'marcasLaser' });
marcaLaserSchema.plugin(uniqueValidator, { message: ' \'{PATH}\' debe ser único.' });
module.exports = mongoose.model('MarcaLaser', marcaLaserSchema);