簡體   English   中英

在 MongoDB 中創建文檔和集合之間的關系

[英]Creating a relationship between a document and a collection in MongoDB

我不知道這是否可能,但我想知道是否有某種方法可以在文檔和整個集合之間建立關系。 我有一個看起來像這樣的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。 我不確定這是否是一回事。 有什么建議? 這甚至可能嗎?

任何幫助表示贊賞。

使用模式背后的想法是創建一種對象關系數據庫模型的感覺。 本文有助於解釋這是如何實現的: NoSQL JSON 文檔數據庫的數據建模指南

使用 NoSQL 數據庫時,我使用了MongooseJS 我想相信它簡單易用。

我希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM