폴링 앱을 만들고 있는데 사용자 ID, IP 주소 또는 MAC 주소를 기반으로 한 설문에 투표 한 사용자를 저장하고 싶습니다.몽구스 - 왜 하위 문서가 작동하지 않습니까?
내 Poll
모델에 voted: VotedSchema
속성을 사용하면 곧바로 앞으로 나아갈 것이라고 생각했지만 어떤 이유로 작동하지 않습니다.
설문 조사 모델 :
const mongoose = require('mongoose');
const { Schema } = mongoose;
const OptionSchema = require('./Option');
const VotedSchema = require('./Voted');
const pollSchema = new Schema({
title: String,
options: [OptionSchema],
dateCreated: { type: Date, default: Date.now() },
_user: { type: Schema.Types.ObjectId, ref: 'User' },
voted: VotedSchema
});
mongoose.model('polls', pollSchema);
투표 subdoc : 다른 한편으로는, 나는 subdoc를 사용하지 않는 경우
const mongoose = require('mongoose');
const { Schema } = mongoose;
const votedSchema = new Schema({
userID: [String],
IPaddress: [String],
MACaddress: [String]
});
module.exports = votedSchema;
는, 그것은 잘 작동 :
const mongoose = require('mongoose');
const { Schema } = mongoose;
const OptionSchema = require('./Option');
const VotedSchema = require('./Voted');
const pollSchema = new Schema({
title: String,
options: [OptionSchema],
dateCreated: { type: Date, default: Date.now() },
_user: { type: Schema.Types.ObjectId, ref: 'User' },
voted: {
userID: [String],
IPaddress: [String],
MACaddress: [String]
}
});
mongoose.model('polls', pollSchema);
나는 무엇인가 놓치고있다. 슈퍼 간단 여기? 이 문제는 다소 당혹 스럽습니다.
당신이 명확히 수, 당신은 참조 하위 문서의 경우에는 작동하지 않는 무엇을 의미합니까? –