猫鼬中用户之间的友好关系简单

时间:2014-05-16 20:19:50

标签: node.js mongodb mongoose relationship

嗨,有人可以向我解释如何在mongoose中写一个简单的友谊关系

var mongoose = require('mongoose'),
Schema = mongoose.Schema;

var User = new Schema({

username:{
    type: String,
    unique: true,
    required: true
},
password:{
    type: String,
    required: true
},
friends:{[

    // stuck here How would i define what another user is here
]}
}

});

1 个答案:

答案 0 :(得分:2)

friends: [{type: Schema.ObjectId, ref: "User"}]