Skip to content

Commit

Permalink
MIM: Avoid errors from _ensure_orig_key when positional $ is used
Browse files Browse the repository at this point in the history
  • Loading branch information
brondsem committed Jun 18, 2020
1 parent 3822601 commit a80a30b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ming/mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,8 @@ def _ensure_orig_key(self, k):
doc = self
for step in path[:-1]:
if isinstance(doc, MatchList):
if step == '$':
return
step = int(step)
if step not in doc._orig:
doc._orig[step] = doc._doc[step]._orig
Expand Down
6 changes: 6 additions & 0 deletions ming/tests/test_mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ def test_inc_dotted_dollar(self):
obj = self.coll.find_one({}, { '_id': 0, 'b.e': 1 })
self.assertEqual(obj, { 'b': { 'e': [ 1,3,3 ] } })

def test_inc_dotted_dollar_middle1(self):
# match on g=1 and $inc by 10
self.coll.update({'b.f.g': 1}, { '$inc': { 'b.f.$.g': 10 } })
obj = self.coll.find_one({}, { '_id': 0, 'b.f': 1 })
self.assertEqual(obj, { 'b': { 'f': [ { 'g': 11 }, { 'g': 2 } ] }})

def test_find_dotted(self):
self.assertEqual(self.coll.find({'b.c': 1}).count(), 1)
self.assertEqual(self.coll.find({'b.c': 2}).count(), 0)
Expand Down

0 comments on commit a80a30b

Please sign in to comment.