forked from CCZX/wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriendly.js
30 lines (26 loc) · 841 Bytes
/
friendly.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 好友数据模型
const DB = require('../utils/connectDB')
const Schema = DB.Schema
const friendlySchema = new Schema({
userM: {
type : Schema.Types.ObjectId,
ref : 'user'
},
userY: {
type : Schema.Types.ObjectId,
ref : 'user'
},
createDate: { type: Date, default: Date.now() }, // 加好友时间
})
friendlySchema.statics.findFriendByUserM = function (userId, cb) { // 联表查询
return this
.find({userM: userId}).populate({path: 'userY', select: 'signature photo nickname onlineTime'})
.exec(cb)
}
friendlySchema.statics.findFriendByUserY = function (userId, cb) {
return this
.find({userY: userId}).populate({path: 'userM', select: 'signature photo nickname onlineTime'})
.exec(cb)
}
const friendly = DB.model('friendly', friendlySchema)
module.exports = friendly