...
for(let i=0; i<data.length; i++){
const result = await postItCollection.updateMany({_id: new ObjectId(data[i].id)}, {$set : {
pinned:data[i].pinned,
style:data[i].style,
userId:data[i].userId,
content:data[i].content,
degree:data[i].degree,
color:data[i].color,
width:data[i].width,
height:data[i].height,
positionX:data[i].positionX,
positionY:data[i].positionY,
positionZ:data[i].positionZ,
}}, {upsert: true});
}
client.close();
res.status(201).json({message: "success"})
const postItCollection = db.collection("fontData");
로 그냥 가져왔다.더욱 더 간단하게 사용가능하다.
async function handler(req, res) {
if (req.method === 'POST') {
const data = req.body;
const client = await MongoClient.connect('mongodb+srv://URL');
const db = client.db();
const postItCollection = db.collection('tableData');
for (const d of data) {
await postItCollection.findByIdAndUpdate(new ObjectId(d.id), d, {
upsert: true,
});
}
client.close();
res.status(201).json({ message: 'success' });
}
}