Skip to content

Commit

Permalink
Fix $set with new keys
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Sep 22, 2024
1 parent d6e4198 commit 7346a2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function run($name, array $params= [], $method= 'write', Session $session
case 'findAndModify':

// Query will always be an ObjectId
$result= &$this->lookup[$params['query']['_id']->string()];
$oid= $params['query']['_id']->string();
$result= $this->lookup[$oid]->properties();
switch (key($params['update'])) {
case '$set':
foreach ($params['update']['$set'] as $name => $value) {
Expand All @@ -65,6 +66,7 @@ public function run($name, array $params= [], $method= 'write', Session $session
}
$ptr= $value;
}
$this->lookup[$oid]= new Document($result);
break;

case '$unset':
Expand All @@ -76,12 +78,13 @@ public function run($name, array $params= [], $method= 'write', Session $session
}
unset($ptr[$segments[$i]]);
}
$this->lookup[$oid]= new Document($result);
break;
}

return new Run(null, null, ['body' => [
'lastErrorObject' => ['n' => 1, 'updatedExisting' => true],
'value' => $result->properties()
'value' => $result
]]);

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function run($name, array $params= [], $method= 'write', Options... $opti
case 'findAndModify':

// Query will always be an ObjectId
$result= &$this->lookup[$params['query']['_id']->string()];
$oid= $params['query']['_id']->string();
$result= $this->lookup[$oid]->properties();
switch (key($params['update'])) {
case '$set':
foreach ($params['update']['$set'] as $name => $value) {
Expand All @@ -65,6 +66,7 @@ public function run($name, array $params= [], $method= 'write', Options... $opti
}
$ptr= $value;
}
$this->lookup[$oid]= new Document($result);
break;

case '$unset':
Expand All @@ -76,12 +78,13 @@ public function run($name, array $params= [], $method= 'write', Options... $opti
}
unset($ptr[$segments[$i]]);
}
$this->lookup[$oid]= new Document($result);
break;
}

return new Run(null, null, ['body' => [
'lastErrorObject' => ['n' => 1, 'updatedExisting' => true],
'value' => $result->properties()
'value' => $result
]]);

default:
Expand Down

0 comments on commit 7346a2f

Please sign in to comment.