mongoose saving referenced nested Objects
-
05-06-2023 - |
Pregunta
I have a Schema which references other Schemes:
var tripSchema = new Schema({
startTime: {type: Date},
endTime: {type: Date},
trackEntries: [{type: ObjectId, ref: 'subSchema1 '}],
user: [{type: ObjectId, ref:'User'}]
});
var subSchema1 = new Schema({
id: Number,
recordTimestamp: Number,
subEntries: [{type: ObjectId, ref:'subSchema2'}]
});
var subSchema2= new Schema({
value: String
});
When i want to save a trip like:
{startTime:"120302203",trackEntries:[{id:0, subEntries:[{value:"1"},{value:"2"}]}], user:{email:"testEmail@domain.tld"}}
I can return the id of that trip but the trip doesn't appear to be in the db. because when i try to run (mongodb console):
db.trips.find();
it returns nothing
Before i defined the sub-Schemas it worked very well. So it should have something to do with the Schemas subSchema1 and subSchema2.
Did i made any mistake?
No hay solución correcta
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow