-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$unset not properly work on multiple field? #1279
Comments
The syntax you have looks correct. Note that the value of the fields in the <?php
require __DIR__ . '/../vendor/autoload.php';
use MongoDB\BSON\UTCDateTime;
use MongoDB\Client;
$client = new Client('mongodb://localhost:27070/?replicaSet=rs0');
$coll = $client->selectCollection('test', 'coll');
$coll->drop();
$coll->insertOne([
'owner_user_code' => 1,
'membership_active_time' => 100,
'membership_renewal_time' => new UTCDateTime(),
'membership_start_date' => new UTCDateTime(),
'membership_type' => 'foo',
'metadata' => ['x' => 1],
'vendor_payment' => 'bar',
]);
var_dump($coll->findOne());
$updateResult = $coll->updateOne(
['owner_user_code' => 1],
['$unset' => [
'membership_active_time' => true,
'membership_renewal_time' => true,
'membership_start_date' => true,
'membership_type' => true,
'metadata' => true,
'vendor_payment' => true,
]],
);
printf(
"\nupdateOne matched %d and modified %d\n\n",
$updateResult->getMatchedCount(),
$updateResult->getModifiedCount(),
);
var_dump($coll->findOne()); Output:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to remove all these field below from certain record :
but the problem is only remove 2 field : membership_renewal_time and metadata, this is my code :
im also tried with
=> false
,=> ""
,=> ''
, but still only deletes certain field like i said aboveThe text was updated successfully, but these errors were encountered: