嗨,有人可以向我解释如何在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
]}
}
});
答案 0 :(得分:2)
friends: [{type: Schema.ObjectId, ref: "User"}]