python 连接mongodb find 不需要取出的字段写法
{ "_id" : ObjectId("5e908fa139cfeaaf0b97b57b"), "Name" : "Chris", "Age" : 21 }
{ "_id" : ObjectId("5e908fa939cfeaaf0b97b57c"), "Name" : "David", "Age" : 23 }
{ "_id" : ObjectId("5e908faf39cfeaaf0b97b57d"), "Name" : "Bob", "Age" : 22 }
{ "_id" : ObjectId("5e908fb539cfeaaf0b97b57e"), "Name" : "Carol", "Age" : 20 }
以下是查询以排除find()-中的某些字段
> db.demo567.find({Name:{$in:["Chris","Bob"]}}, {Age:0,_id:0});
这将产生以下输出-
{ "Name" : "Chris" }
{ "Name" : "Bob" }
{ "_id" : ObjectId("5e908fa139cfeaaf0b97b57b"), "Name" : "Chris", "Age" : 21,"sta_date":"2022-07-20", "update_time":ISODate("2022-07-17T13:39:47.106Z")}
{ "_id" : ObjectId("5e908fa939cfeaaf0b97b57c"), "Name" : "David", "Age" : 23 ,"sta_date":"2022-07-20", "update_time":ISODate("2022-07-17T13:39:48.106Z")}
{ "_id" : ObjectId("5e908faf39cfeaaf0b97b57d"), "Name" : "Bob", "Age" : 22 ,"sta_date":"2022-07-20", "update_time":ISODate("2022-07-17T13:39:48.106Z")}
{ "_id" : ObjectId("5e908fb539cfeaaf0b97b57e"), "Name" : "Carol", "Age" : 20 ,"sta_date":"2022-07-20", "update_time":ISODate("2022-07-17T13:39:48.106Z")}
itemslist = db.demo567.find({"sta_date" : "2022-07-20"}, {'_id': 0,'sta_date':0,'update_time':0})
输出结果:
{ "Name" : "Chris", "Age" : 21}
{"Name" : "David", "Age" : 23 }
{"Name" : "Bob", "Age" : 22 }