使用ExpressJS的Mongoose多查询运算符

时间:2018-08-09 22:45:13

标签: node.js mongodb express mongoose api-design

我正在尝试学习如何制作API。我遇到了一个超越我的问题。我的问题是关于数据库查询。这是我的终点;

/api/stats/:userId/:period/:type/:point?/

:userId确实是用户ID(就像Twitter一样是雪花ID)

:period始终带有时间戳记。 (稍后我将其称为start_date

:type是用户操作。

:point?是一个可选参数,表示 speific 用户操作。

所以,这是我的猫鼬模式;

id: String, // this is timestamp
userId: String,
point: String,
type: String

,我需要一个包含所有这些参数的数据库查询。但有所不同。必须间隔一定的时间。所以,尝试了这个;

user.find({
    $and: [{ id: { $gte: start_date } }, { id: { $lte: end_date } }]
}).exec()

但是如何在此查询中添加其他参数(userIdtype,如果有point)?我一整天都在搜索,但是找不到。

0 个答案:

没有答案
相关问题