From faafb15b3adbc2b900451bb7ec32a70962439d57 Mon Sep 17 00:00:00 2001 From: Beni Cherniavsky-Paskin Date: Tue, 20 Feb 2024 13:42:12 +0200 Subject: [PATCH] pymongo: use projection=[] instead of fields={} With current pymongo==3.13.0, was causing exception: TypeError: __init__() got an unexpected keyword argument 'fields' Not sure when pymongo API changed; oldest doc I found online https://pymongo.readthedocs.io/en/3.5.1/api/pymongo/collection.html#pymongo.collection.Collection.find which doesn't mention `fields=` only `projection=`. Change from {x: 1} to ['x'] style is cosmetic, reads less magic to me, but `projection` arg supports both. --- explainshell/store.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/explainshell/store.py b/explainshell/store.py index 6cadaf0b..cf0cf569 100644 --- a/explainshell/store.py +++ b/explainshell/store.py @@ -356,7 +356,7 @@ def updatemanpage(self, m): logger.info('updating manpage %s', m.source) m.updated = True self.manpage.update({'source' : m.source}, m.to_store()) - _id = self.manpage.find_one({'source' : m.source}, fields={'_id':1})['_id'] + _id = self.manpage.find_one({'source' : m.source}, projection=['_id'])['_id'] for alias, score in m.aliases: if alias not in self: self.addmapping(alias, _id, score) @@ -369,7 +369,7 @@ def verify(self): # check that everything in manpage is reachable mappings = list(self.mapping.find()) reachable = set([m['dst'] for m in mappings]) - manpages = set([m['_id'] for m in self.manpage.find(fields={'_id':1})]) + manpages = set([m['_id'] for m in self.manpage.find(projection=['_id'])]) ok = True unreachable = manpages - reachable @@ -386,12 +386,12 @@ def verify(self): return ok, unreachable, notfound def names(self): - cursor = self.manpage.find(fields={'name':1}) + cursor = self.manpage.find(projection=['_id', 'name']) for d in cursor: yield d['_id'], d['name'] def mappings(self): - cursor = self.mapping.find(fields={'src':1}) + cursor = self.mapping.find(projection=['_id,', 'src']) for d in cursor: yield d['src'], d['_id']