私はmongodbを初めて使用し、過去数日間、mongolabインスタンスにエントリを取得しようとしましたが、運がありませんでした. 保存呼び出しを実行すると、次のエラーが表示されるようです。
TypeError: Cannot use 'in' operator to search for '_id' in [object Object]
彼らが参照している [オブジェクト オブジェクト] は、私のカラー スキーマです。私はまだ答えを見つけることができなかったので、ここに投稿して、さらに調査しながら並行して作業しようと思いました. 私が使っているもののスニピットを貼り付けました。ティア!
mongoose.connect(config.db.mongodb);
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var Color = new Schema({
hex : {type:String, required: true, trim: true}
,perc : {type:String, required: true, trim: true}
});
var Img = new Schema({
path : {type:String, required: true, trim: true}
,color : [Color]
});
var imgModel = mongoose.model('Img', Img);
exports.addImage = function(req,res){
//First check to see if we already have the image stored
imgModel.findOne({path: req.query.path}, function(error, image){
if(error){
console.log("Error");
res.json(error);
}
else if(image === null){
//There is no image so just store the info
var image_data = {
path: req.query.path,
color: req.query.color
};
var img = new imgModel(image_data);
img.save(function(error, data){
//*** This error block below is where I am
// entering and the message is displayed
if(error){
console.log("Oh noo: ",error);
res.json(error);
}
else{
console.log("Saving: ",data);
res.json(data);
}
});
} else{
//The path is already here
//res.json("Image already in db");
console.log("Image already in db");
}
});
};