我什至不知道这是否可能,但我想找出是否有某种方法可以在文档和整个馆藏之间建立关系。我有一个user
模式,看起来像这样:
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}
});
要实现我期望的目标,我认为我的模式需要看起来像这样:
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
});
这种方法的问题是,我无法获取集合的ID。我不确定这是否是一回事。有什么建议?这有可能吗?
感谢您的帮助。
答案 0 :(得分:0)
使用模式背后的想法是创建一种对象关系数据库模型。本文有助于说明如何实现此目标:Data Modeling Guidelines for NoSQL JSON Document Databases。
使用NoSQL数据库时,我使用了MongooseJS。我想相信它简单易用。
我希望这会有所帮助。