app.post("/api/orders", async(request, response) => {
try {
await client.connect();
console.log("Connected correctly to server");
const db = client.db(dbName);
// Use the collection
console.log("search options " + json(request));
const col = db.collection("Orders");
// const inserted = await col.insertOne();
response.send("thanks")
} catch (err) {
console.log(err.stack);
}
});
/
let orderData = {subject: "subject", location: "location", price:"price", spaces: "spaces"};
const optionsPOST = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(orderData)
};
console.log(JSON.stringify(orderData))
fetch("/api/orders", optionsPOST);
I am trying to post some data that then is added to mongodb atlas, however, when I post my data I get undefined.
question from:
https://stackoverflow.com/questions/65945302/why-is-expressjs-post-request-returning-object-object 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…