根据pymongo根据条件获取数据
我正在尝试根据基于过滤器的查询获取数据。现在,我正在使用
filter_stuff = {'url': 1, 'organization_name': 1, 'hum_pred':1, 'ml_pred':1, '_id': 0}
myData = list(crawlcol.find({'hum_pred': 'null'}, filter_stuff))
此功能将获取数据,其中hum_pred
具有值null
。
hum_pred
和ml_pred
将具有值有效
无效
或null
具有字段值的获取数据hum_pred为null
和ml_pred有效或无效
示例数据
[
{"url":"www.example1.com","organization_name":"abc","ml_pred":"Valid", "hum_pred":"invalid"},
{"url":"www.example2.com","organization_name":"gvg","ml_pred":"Invalid", "hum_pred":"null"},
{"url":"www.example3.com","organization_name":"hsg","ml_pred":"null", "hum_pred":"null"},
{"url":"www.example4.com","organization_name":"hga","ml_pred":"Valid", "hum_pred":"valid"},
{"url":"www.example5.com","organization_name":"tre","ml_pred":"Invalid", "hum_pred":"valid"}
]
预期的输出
[{"url":"www.example2.com","organization_name":"gvg","ml_pred":"Invalid", "hum_pred":"null"}]
I am trying to fetch data based on filter based queries. Right now I am using
filter_stuff = {'url': 1, 'organization_name': 1, 'hum_pred':1, 'ml_pred':1, '_id': 0}
myData = list(crawlcol.find({'hum_pred': 'null'}, filter_stuff))
This will fetch data where hum_pred
have values null
.
hum_pred
and ml_pred
will have values valid
invalid
or null
How is it possible to fetch data which has field values hum_pred is null
and ml_pred is valid or invalid
sample data
[
{"url":"www.example1.com","organization_name":"abc","ml_pred":"Valid", "hum_pred":"invalid"},
{"url":"www.example2.com","organization_name":"gvg","ml_pred":"Invalid", "hum_pred":"null"},
{"url":"www.example3.com","organization_name":"hsg","ml_pred":"null", "hum_pred":"null"},
{"url":"www.example4.com","organization_name":"hga","ml_pred":"Valid", "hum_pred":"valid"},
{"url":"www.example5.com","organization_name":"tre","ml_pred":"Invalid", "hum_pred":"valid"}
]
Expected Output
[{"url":"www.example2.com","organization_name":"gvg","ml_pred":"Invalid", "hum_pred":"null"}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查询就像
The query will be like
查询
“ null”
,因此使用字符串用于null
$或and&and&and&and $ eq
或 in 喜欢bellow( in in 的 $ in CODACT)*如果您只有3个可能的值
ML_PRED
@imhans4305答案甚至更短,所以我认为另一个答案是在通常的情况下,这就是您可以做到的。
playmongo
Query
"null"
, so strings are used fornull
$or and $eq
or$in
like bellow ($in
is more compact for this use)*if you have only 3 possible values for
ml_pred
the @imhans4305answer is even shorter, so go for the other i think, this is how you could do it in general case.
Playmongo