Creating Data with POST
メニューを表示するにはスワイプしてください
To store data in MongoDB, you create a new document using a model.
This is usually done in a POST route.
app.post('/users', async (req, res) => {
const user = new User(req.body);
const savedUser = await user.save();
res.json(savedUser);
});
The data comes from req.body. A new instance of the model is created and then saved to the database.
After saving, the stored document is returned as a response.
Example request body:
{ "name": "John", "age": 25 }
This creates a new record in the database.
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 7
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください
セクション 1. 章 7