mongodb - mongoDB中的条件过滤
问题描述
我可以有条件地使用 $and 过滤器之一,即。当满足某些条件时,我想使用过滤器,否则不要使用过滤器:
Collection.find({
$and: [
{ date },
{ room: [isConditionMet] ? room : [do not use room filter at all] },
]
}
是否可以在 mongo 查询级别?
解决方案
不是和使用$or一样吗?
Collection.find({
$and: [
{ date: ... },
{ $or: [
{isConditionNOTmet},
{room: ... }
]}
]
})
推荐阅读
- ios - 从 Xcode Run Script 获取 xcconfig 配置文件名
- firebase - 在 Firebase 项目中存储机密:Firebase 配置 API 还是 Secret Manager API?
- gtsummary - 使用 inline 在 gtsummary 中获取组大小
- asp.net - 脚手架时尝试激活控制器时无法解析服务上下文
- javascript - 为 mongodb 中的现有值添加价值
- azure - AADSTS90027 我们无法在 MSA 租户上从此 API 版本颁发令牌
- node.js - 使用 express-validator 验证对象数组
- flutter - Overalyed 图像不会在颤动中出现在左下角
- php - 如果值等于,则使用 OR 语句回显一次
- python - 无法使用 importlib 在 python 3.8.8 中导入文件