数据结构:
[
{
"from_site": "sosovalue",
"id": "e7b0311a8b2f49ec8ba6736980602efc",
"name": "Daily Total",
"search_name": "bitcoin spot etf daily total",
"last_updated": 1710227808551,
"last_updated_utc": "2024-03-12 07:16:48.551212",
"total_page": "1",
"total": "41",
"list": [
{
"id": "1766329029461434369",
"data_date_utc": "2024-03-08 00:00:00",
"data_date_timestamp": 1709856000,
"total_net_inflow": 222986549.0,
"total_volume": 7691454370.0,
"total_net_assets": 55499316412.0,
"total_cum_net_inflow": 9588465608.095,
"total_net_inflow_change": -0.005281231226684967,
"total_volume_change": 0.006257883132371463,
"total_net_assets_change": 0.0002607192862848633,
},
{
"id": "1766030876727517185",
"data_date_utc": "2024-03-07 00:00:00",
"data_date_timestamp": 1709769600,
"total_net_inflow": 472552396.0,
"total_volume": 4730907651.0,
"total_net_assets": 54089109022.0,
"total_cum_net_inflow": 9365479059.095,
"total_net_inflow_change": 0.0042307911230247686,
"total_volume_change": 0.0006264197177240608,
"total_net_assets_change": 0.00018353606574301982,
}
]
}
]
我想以 “name”: “Daily Total”,和list中的id为条件,做查询语句,但是网上的一些写法总是不能够很好的过滤掉list中不符合的字段。
通常的写法是这样:
db.bitcoin_etf_tracker.find({
"name": "Daily Total",
"list.id": "1766329029461434369"
}
)
这样的写法,查询的结果是list.id过滤条件完全不起作用,
有效的写法
db.bitcoin_etf_tracker.find({
"name": "Daily Total",
"list.id": "1766329029461434369"
},
{
"_id": 0,
"name": 1,
"list.$": 1
}
)