mongodb python gridfs.find()条件查询

https://docs.mongodb.com/manual/reference/operator/query/ 条件查询的类型说明

查询的格式

for grid_out in gridFS.find({"filename":{"$regex":"/c/"}}): 这样可以匹配到所有以c开头的名称

但是通常我们查的是id,如果直接这样查id会没有结果的,因为再mongodb中,id中一种objectid对象,应该有其他形式,但是楼主没找到,因此换了一种方式

ID匹配的方式,需要引入 from bson.objectid import ObjectId

但此种方式,不知道如何使用正则(留作以后探索),因此采用第二种方式

for grid_out in gridFS.find({ "_id": ObjectId("5be14a3beefc3218a0812e16")}):

采用where来,取得id对象的字符串来进行正则匹配 

for grid_out in gridFS.find({ "$where": "this._id.str.match(/.*5be14/)"}):

对于linux下的系统,去掉str。。耗费2小时找不到,瞎猜的..懵对了。。太难

for grid_out in gridFS.find({ "$where": "this._id.match(/.*5be14/)"}):

猜你喜欢

转载自blog.csdn.net/A873054267/article/details/84025731