가 Mongoose Docs에 따라, 그 이식 후 통지 스키마에 대한 참조를 사용하여 : 어떤 것은이 구조를 생산하기 위해 그렇게 할 수있는 가장 좋은 방법이 될 것입니다.
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId,
var notificationSchema = new Schema({
initiator: { type: ObjectId, ref: 'User' }
});
var Notification = mongoose.model('Notification', notificationSchema);
그런 다음 사용할 수 있습니다 몽구스의 query populate method 그러나
app.get('/notifications/:id', function(req, res) {
Notification
.find({ initiator: req.params.id })
.select('_id type initiatorId')
.populate('initiator')
.exec(function(err, notifications) {
if (err) return handleError(err);
// do something with notifications
});
});
, 나는 ID가 사용자 ID (그리고 알림 ID가) 왜 조금 혼란 스러워요 -이 API를 사용한다면 그 나를 혼란스럽게 할 것입니다.
정확히을 원하는 데이터 구조로 만들지는 못하지만, 그런 경우라면 "올바른"방식이라고 생각합니다. `var에 notificationSchema = mongoose.Schema ({ userId를 : : 문자열, // 유형을이다 : 문자열, initiatorId : 문자열, // 통지를 읽기를 보내
이 내 통지 스키마입니다 : Boolean, date : Date });' – benhowdle89