node.js - 带有 expressjs 的 Mongoose 多查询运算符
问题描述
我正在尝试学习如何制作 API。我遇到了一个超越我的问题。我的问题是关于数据库查询。这是我的终点;
/api/stats/:userId/:period/:type/:point?/
:userId
完全是用户 ID(它是像 twitter 一样的雪花 ID)
:period
总是有一个时间戳。(我稍后会调用它start_date
)
:type
是用户操作。
:point?
是一个可选参数,它意味着特定的用户操作。
所以,这是我的猫鼬模式;
id: String, // this is timestamp
userId: String,
point: String,
type: String
我需要一个包含所有这些参数的数据库查询。但有区别。它必须在一定的时间间隔内。所以,试试这个;
user.find({
$and: [{ id: { $gte: start_date } }, { id: { $lte: end_date } }]
}).exec()
但是如何在这个查询中添加其他参数( userId
,type
如果有)?point
我搜索了一整天,但我找不到它。
解决方案
推荐阅读
- ruby-on-rails - 如何从 Redis INFO 获取特定值
- python - Apache AIRFLOW - 如何将参数发送到 Python 脚本
- crystal-lang - 为什么在信号陷阱块中杀死的进程会变成僵尸而不是定期终止?
- java - 无法通过限定符注入
- java - 在webdriver java中将凭证循环为数组
- c# - IActivityLogger 不记录 PromptDialog.Choice 文本
- reactjs - 无需摇动 React Native 即可打开 Dev Menu 或重新加载应用程序
- java - 在 Java 中进行远程调用时要处理哪些异常
- r - 使用 tryCatch 记录失败的第 i 次迭代
- java - 我可以在 JPA 中修改 id 类型,从“int”到“long”而不影响 DB 中已经存在的表中的数据吗