私は質問集を持っており、私は店舗モデルを持っています。私は、ストアモデルの質問フィールドを質問コレクションのオブジェクトIDの配列にする必要があります。私は後で人口を使用することができます。将来app.getを実行すると、ストア情報とすべての質問のあるドキュメントが表示されるはずです。文書を取り込む方法や参照を保存する方法
var Schema = mongoose.Schema;
var storeSchema = Schema({
name : {type : String},
industry : {type : String},
questions :[{type : Schema.Types.ObjectId, ref : "Questions" }]
})
var questionsSchema = Schema({
question : {type :String}
})
var store = mongoose.model("Store", storeSchema);
var questions = mongoose.model("Questions", questionsSchema)
// questions.create({question: "question2"}, function(err,q){
// console.log("create: " , q)
// })
//something like this
questions.find({}, function(err, doc){
store.create({name : "store 1", industry : "industry 1" , questions : /*get the _ids from the question collection*/ {$push : doc.question}})
})
> db.questions.find().pretty()
{
"_id" : ObjectId("574534a289763c004643fa08"),
"question" : "question1",
"__v" : 0
}
{
"_id" : ObjectId("574534acc90f3f2c0c3d529b"),
"question" : "question2",
"__v" : 0
}
>
@jack_blankあなたは、このためのソリューションを見つけましたか? –