提问人:Kerby Elpenord 提问时间:9/30/2023 更新时间:9/30/2023 访问量:28
我想将我的数据从编辑器.js传输到mongodb图集
I want to transfert my data from editor.js to mongodb atlas
问:
嗨,想将我的数据发送到mongodb,但我的块无法转到我的数据库。数据来自编辑器.js
这些是我的模式:
const dataBlockSchema = new Schema({
text: String,
})
const BlockSchema = new Schema({
type: Schema.Types.Mixed,
data: [dataBlockSchema],
});
const EditorSchema = new Schema({
time: Number,
blocks: [BlockSchema],
version: String
});
const EditorModel = mongoose.model('Editor', EditorSchema);
这是我发布数据的功能:
async function post_data(outputData) {
console.log('outputData:', outputData.blocks[0]); // Log outputData for debugging
try {
let options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
blocks: outputData.blocks,
time: outputData.time,
version: outputData.version,
}),
};
const resp = await fetch(URL, options);
const data = await resp.json();
console.log('Server response:', resp); // Log server response for debugging
} catch (err) {
return console.log(err);
}
}
答: 暂无答案
评论