Ref with string in mongoose

I have two models

 var Passenger = mongoose.model('passengers', new Schema({
        username: {
            type: String,
            ref: 'users'
        },
        company: String,
        baggage: String,
        note: String,
        owner: String
    }));


    var User = mongoose.model('users', new Schema({
        username: String,
        first: String,
        last: String,
        email: String,
        password: String
    }));

      

I would really like to get a full user instead of a passenger with a username. I thought ref and populate would be the way to do this.

Trip.find({
        request: true
    }).populate('flights.users').exec(function (err, trips) {

});

      

The top-level document - "Trip" and "Flights" is an array under "Trips", and "Passengers" is an array under "Flights".

It's impossible. Should I give my users all IDs instead?

Thanks for the help.

+3
node.js mongodb mongoose


source to share


No one has answered this question yet

Check out similar questions:

1186
Convert JS object to JSON string
305
How do I update / update a document in Mongoose?
274
What is "__v" field in Mongoose?
five
NodeJs, Mocha and Mongoose
2
Mongoose by email
2
Mongoose cultivar by populated field
1
How to achieve DBRef for virtual
0
Mongoose filling link not defined
0
after saving in mongoose {strict: false}, cannot edit after findOne ()
0
Mongoose schema for link arrays with role



All Articles
Loading...
X
Show
Funny
Dev
Pics