我怎么能得到基于mongodb值的所有字段数据?



我想做的是根据一个键和值为createdBy: phoneNumber的参数获取用户拥有的所有信息。首先,我想在请求体中放入电话号码,并使用find()方法查找基于该电话号码的数据库中的所有数据,但我发现get方法不接受请求体。

exports.getLocation = asyncHandler(async (req, res, next) => {
const getLocation = await Location.find( req.params.createdBy )
res.status(200).json({
success: true,
msg: "Getting all the locations of the user",
data: getLocation
})
}) 

路线
/**
* @swagger
* /location/getLocation:
*   get:
*     summary: getting the location of the user by phone number
*     tags: [Location]
*     requestBody:
*       required: false
*       content:
*        application/json:
*          schema:
*            $ref: '#/components/schemas/Location'
*
*     responses:
*       200:
*         description: the location has been recivied
*       500:
*         description: Some server error
*/
router.get("/getLocation", getLocation) 

我如何通过将值作为请求从db获得所有数据?

你甚至不发送参数。要发送一个参数,你需要做以下事情:

router.get("/getLocation/:createdBy", getLocation)

然后你需要提出这样的请求:http://example.com/getLocation/somedata

req.params.createdBy则为somedata

相关内容

  • 没有找到相关文章

最新更新