【发布时间】:2021-08-16 21:28:16
【问题描述】:
首先,我使用他的电子邮件和密码注册了一个用户。
现在如果
我尝试在注册用户时通过匹配 Mongo 数据库分配的 ID 来更新或制作用户详细信息。
它不接受它。
错误是这样的
Parameter "filter" to find() must be an object, got 60b10821af9b63424cf427e8
如果我像这样解析它
Model.find(parseInt(req.params.id))
它显示一个不同的错误。
这里是发布请求
//Post request to create user details by matching Id.
// Id I am trying to match is the id that was given by the database
app.post("/user/:id", async(req, res) => {
console.log("not found");
if (await Model.find(req.params.id)) {
const users = new Model({
fName: req.body.fName,
sName: req.body.sName,
birth: req.body.birth,
phone: req.body.phone,
SSN: req.body.SSN
});
const result = await users.save();
console.log(result);
return res.send({
"Success": true,
});
} else {
console.log(req.params.id);
res.status(404).send({ "message": false });
}
});
这是架构
const LoginSchema = new mongoose.Schema({
email: { type: String, required: true },
password: { type: String, required: false },
otp: String,
token: String,
fName: String,
sName: String,
birth: Number,
phone: Number,
SSN: Number
});
这是我使用的标题
const express = require("express");
const app = express();
const mongoose = require("mongoose");
app.use(express.json());
app.use(express.urlencoded({ extend: true }));
Database id assigned which I use
{
_id: 60b1131271129a3cf8275160,
email: 'Pak@gmail.com',
password: '$2b$10$FWAHu4lP9vn14zS/tWPHUuQJlO7mjAUTlPj.FliFAZmCNA23JA3Ky',
__v: 0
}
【问题讨论】:
标签: node.js mongodb mongoose postman