当从Pythons MongoClient请求数据(连接到相同的数据库并从相同的集合请求)时,我的结果(带有或不带有过滤)的结果变少了
for example requesting db.collection.find({})
在外壳中给我12个结果,而在pymongo中相同的查询给我8个,缺少4个,使用过滤后,我得到一个结果而不是4个(对于那些丢失的东西)
还有其他人遇到python mongoclient的麻烦吗?
在外壳中运行时
db.test.find() i get the result
{ "_id" : ObjectId("5b581e4bd8624400b4138044"), "account" : "1234", "job_id" : ObjectId("5b473177310ea1023a4f434f"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.780Z") }
{ "_id" : ObjectId("5b581e4bd8624400b4138045"), "account" : "12345", "job_id" : ObjectId("5b3f36df42db3e021a3b2689"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.929Z") }
{ "_id" : ObjectId("5b581e4bd8624400b4138046"), "account" : "32124", "job_id" : ObjectId("5b43bf9a51dac70058ffa43c"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.856Z") }
{ "_id" : ObjectId("5b581e4bd8624400b4138047"), "account" : "44112", "job_id" : ObjectId("5b4a464c94e89c00cb61d001"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-26T04:00:58.803Z") }
{ "_id" : ObjectId("5b581e4bd8624400b4138049"), "account" : "44115", "job_id" : ObjectId("5b56d464d862440046ccf1fa"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.764Z") }
{ "_id" : ObjectId("5b581e4bd8624400b413804a"), "account" : "414141", "job_id" : ObjectId("5b473ea7310ea10827c4886b"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.986Z") }
{ "_id" : ObjectId("5b58623a89ca2c00755e12d7"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b695283f"), "area" : "238428477", "start" : false, "tag" : "nice", "time" : ISODate("2018-07-25T22:00:50.009Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12da"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "time" : ISODate("2018-07-25T17:42:57.022Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12db"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "cat" : "70058", "time" : ISODate("2018-07-25T11:43:57.483Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12dc"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "cat" : "70058", "time" : ISODate("2018-07-25T11:43:57.488Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12dd"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "cat" : "70058", "time" : ISODate("2018-07-25T11:43:57.493Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12de"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "cat" : "70058", "time" : ISODate("2018-07-25T11:43:57.497Z") }
when db.test.find({"account":"444444", "tag": "nice"}) i get
{ "_id" : ObjectId("5b58623a89ca2c00755e12d7"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b695283f"), "area" : "238428477", "start" : false, "tag" : "nice", "time" : ISODate("2018-07-25T22:00:50.009Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12da"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "time" : ISODate("2018-07-25T17:42:57.022Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12db"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "cat" : "70058", "time" : ISODate("2018-07-25T11:43:57.483Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12dc"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "cat" : "70058", "time" : ISODate("2018-07-25T11:43:57.488Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12dd"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "cat" : "70058", "time" : ISODate("2018-07-25T11:43:57.493Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12de"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "cat" : "70058", "time" : ISODate("2018-07-25T11:43:57.497Z") }
对于通过PyMongo进行的相同查询,我得到
(no filter)
{ "_id" : ObjectId("5b581e4bd8624400b4138044"), "account" : "1234", "job_id" : ObjectId("5b473177310ea1023a4f434f"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.780Z") }
{ "_id" : ObjectId("5b581e4bd8624400b4138045"), "account" : "12345", "job_id" : ObjectId("5b3f36df42db3e021a3b2689"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.929Z") }
{ "_id" : ObjectId("5b581e4bd8624400b4138046"), "account" : "32124", "job_id" : ObjectId("5b43bf9a51dac70058ffa43c"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.856Z") }
{ "_id" : ObjectId("5b581e4bd8624400b4138047"), "account" : "44112", "job_id" : ObjectId("5b4a464c94e89c00cb61d001"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-26T04:00:58.803Z") }
{ "_id" : ObjectId("5b581e4bd8624400b4138049"), "account" : "44115", "job_id" : ObjectId("5b56d464d862440046ccf1fa"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.764Z") }
{ "_id" : ObjectId("5b581e4bd8624400b413804a"), "account" : "414141", "job_id" : ObjectId("5b473ea7310ea10827c4886b"), "start" : false, "tag" : "hello", "time" : ISODate("2018-07-25T22:00:58.986Z") }
{ "_id" : ObjectId("5b58623a89ca2c00755e12d7"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b695283f"), "area" : "238428477", "start" : false, "tag" : "nice", "time" : ISODate("2018-07-25T22:00:50.009Z") }
{ "_id" : ObjectId("5b58624189ca2c00755e12da"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "time" : ISODate("2018-07-25T17:42:57.022Z") }
(acccount and tag filter)
{ "_id" : ObjectId("5b58624189ca2c00755e12da"), "account" : "444444", "job_id" : ObjectId("5b58623989ca2c00b995283f"), "area" : "238428477", "start" : false, "tag" : "nice", "time" : ISODate("2018-07-25T17:42:57.022Z") }
我如何通过pymongo连接
host = config['host']
port = config['port']
db_name = config['db_name']
db = MongoClient(host, port)[db_name]
and then i just run with and without filters, still different result
db.collection.find()