Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,6 @@ public function insert(string $collection, array $document, array $options = [])
$docObj = new stdClass();

foreach ($document as $key => $value) {
if (\is_null($value)) {
continue;
}

$docObj->{$key} = $value;
}

Expand All @@ -486,10 +482,6 @@ public function insertMany(string $collection, array $documents, array $options
$docObj = new stdClass();

foreach ($document as $key => $value) {
if (\is_null($value)) {
continue;
}

$docObj->{$key} = $value;
}

Expand Down Expand Up @@ -540,22 +532,13 @@ public function lastDocument(string $collection): array
*/
public function update(string $collection, array $where = [], array $updates = [], array $options = [], bool $multi = false): self
{
$cleanUpdates = [];

foreach ($updates as $k => $v) {
if (\is_null($v)) {
continue;
}
$cleanUpdates[$k] = $v;
}

$this->query(
array_merge([
self::COMMAND_UPDATE => $collection,
'updates' => [
[
'q' => $this->toObject($where),
'u' => $this->toObject($cleanUpdates),
'u' => $this->toObject($updates),
'multi' => $multi,
'upsert' => false
]
Expand All @@ -582,16 +565,9 @@ public function upsert(string $collection, array $operations, array $options = [
$updates = [];

foreach ($operations as $op) {
$cleanUpdate = [];
foreach ($op['update'] as $k => $v) {
if (!is_null($v)) {
$cleanUpdate[$k] = $v;
}
}

$updateOperation = [
'q' => $op['filter'],
'u' => $this->toObject($cleanUpdate),
'u' => $this->toObject($op['update']),
'upsert' => true,
'multi' => isset($op['multi']) ? $op['multi'] : false,
];
Expand Down Expand Up @@ -897,12 +873,7 @@ private function cleanFilters($filters): array

if (in_array($k, ['$and', '$or', '$nor']) && is_array($v)) {
$values = [];

foreach ($v as $item) {
if (is_null($item)) {
continue;
}

$values[] = is_array($item) ? $this->toObject($item) : $item;
}

Expand Down