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.
The idea behind using schema is to create a sense of an object-relational database model. This article helps to explain how this is achieved: Data Modeling Guidelines for NoSQL JSON Document Databases.
When using NoSQL databases I used MongooseJS. I would want to believe it is simple and easy to use.
I hope this helps.