Mongodb type reference node

后端 未结 4 1373
情深已故
情深已故 2021-02-18 22:25

I am trying reference another object in a model in node,

User = new Schema({
        username: {
            type: String,
            index: {unique: true}
             


        
4条回答
  •  不思量自难忘°
    2021-02-18 22:43

    I found out the answer to my own question here it is.

    User = new Schema({
        username: {
            type: String,
            index: {unique: true}
        }
    });
    
    Idea = new Schema({
        Creator: {
            type: Schema.ObjectId,
            ref: 'User'
        }
    });
    

提交回复
热议问题