私はプラントと呼ばれる私のコレクションにデータセットをロードしました。ここでは植物の例です:私は私のコレクションを更新する必要がMeteorは関数からMongodbデータを操作します
{
"_id": "zGdXzfFTAzhrhCvqE",
"Plant": "Carrot",
"Companions": ["Beetroot", "Dandelion", "Rose"]
}
ので、各コンパニオンは、(_idを持つ)レコードですので、最初の「私は仲間がすでに_idを持っているかどうかを確認する必要がありますが、私ができます構文が正しいと思われる。
//why does'nt this work?
var com = Plants.find({"Plant": "Thyme"});
console.log("id: " + com._id); //returns undefined, even though it exists in the collection
//this works
Plants.find({}).forEach(function(plant){
var companions = plant.Companions;
console.log(companions[0]); //prints out the first plantname in the array
//here I need to check if the plant is already in the collection
for(var i = 0; i < companions.length; i++){
var com_plante = Plants.findOne(companions[i]);
//this writes out undefined
console.log("com_plante: " + com_plante._id + " " + com_plante.Plant);
}
}
構文にはどのような問題がありますか?代わり
ありがとうございました。私はまだ別の初心者です... – Heidi