我使用的猫鼬用MongoDB的v3.4.3如何将另一个架构数据添加到模型中?
下面是我的图像模型代码
const mongoose = require("mongoose");
const CoordinateSchema = require("./coordinate");
const ImageSchema = new mongoose.Schema({
image_filename: {
type: String,
required: true
},
image_url: {
type: String,
required: true
},
coordinates: [CoordinateSchema],
});
下面是我CoordinateSchema代码
const mongoose = require("mongoose");
const CoordinateSchema = new mongoose.Schema({
coordinates : {
type: Array,
default: [],
}
});
module.exports = CoordinateSchema;
下面是在快递运行我的API的js代码,
router.post('/receiveCoordinates.json', (req, res, next) => {
Image.findOneAndUpdate({image_filename:req.body.file_name}).then((image) => {
})
});
如何完成此代码,所以我c商店坐标数据在图像模型中。
谢谢。
你使用什么版本的猫鼬? –
@JoseLopezGarcia我正在使用Mongodb v3.4.3。我更新了问题,我发现我可以使用findOneAndUpdate – Dreams
我问你的猫鼬版本,而不是MongoDB!顺便检查我的答案,如果它不起作用,让我知道,所以我们可以制定一个解决方案 –