0

I have no idea if this is even possible but I'd like to find out if there's some way to create a relationship between a document and a whole collection. I have a user schema that looks something like this:

var userSchema = new Schema({
    fname: {type: String, required: true},
    lname: {type: String, required: true},
    email: {type: String, required: true, unique: true},
    password: {type:String, required: true}
});

To achieve my desired goal, I'm thinking my schema would need to look a bit like this:

var userSchema = new Schema({
    fname: {type: String, required: true},
    lname: {type: String, required: true},
    email: {type: String, required: true, unique: true},
    password: {type:String, required: true},
    collections: [{type: Schema.Types.ObjectId}] // where ObjectId would be the ID to a collection

});

The problem with this approach is, I have no way to get the ID of a collection. I'm unsure if that's even a thing. Any suggestions? Is this even possible?

Any help is appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.