Question

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 correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top