Pymongo-如何忽略查询中的参数
在一行使用Pymongo查询文档时,有没有办法忽略参数?例如:
db.find_one( { "first_name": firstname, "last_name": lastname, "age": age if age else <ignore this field from querying all together> } ):
Is there a way to ignore a parameter when querying documents using PyMongo in one line? For example:
db.find_one( { "first_name": firstname, "last_name": lastname, "age": age if age else <ignore this field from querying all together> } ):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
$和
和$或
运算符。$和
- match 1.1。和 1.2。条件。1.1。匹配
first_name
和last_name
。1.2。
$或
- 匹配age
变量为null或age
与age
age 变量匹配。示例mongo playground
Work with
$and
and$or
operators.$and
- Match 1.1. and 1.2. conditions.1.1. Match
first_name
andlast_name
.1.2.
$or
- Matchage
variable is null orage
field match withage
variable.Sample Mongo Playground
您可以尝试以下几种方法:
- 或 -
或 - (与上述相同)
Here are couple of ways you can try:
-OR-
-OR- (same as above)