Tuesday 9 May 2017

Dont know how to populate Mongoose Query

I have a problem with a mongoose population and I don't know what I should do.

I got two schemas:

var userSchema =  new userSchema({
    username: { type: String, required: true, unique: true },
    password: { type: String, required: true },
    mods: [{ type: mongoose.Schema.Types.ObjectId, ref: 'users'}]
});
var dataSchema = mongoose.Schema({
    title: { type: String, required: true, unique: true },
    description: { type: String, required: true },
    owner: {type: mongoose.Schema.Types.ObjectId, required: true}
});

So one user can have several data packages. Some users are moderated by other users.

Whats the query for a moderator, that all his own data packages and the ones of the users he is moderating are listed?

You see that I have a SQL background and there's definitely another way to do it with MongoDB.

Thanks for your help!



via user3382944

No comments:

Post a Comment