1

I have the following document:

"parameters" : [
    {
        "592193d6470e6cf80d3c9874" : {
            "Speed" : "1",
            "Acceleration" : "2"
        }
    }]

I need to pull element by key 592193d6470e6cf80d3c9874.

I tried:

 $this->collection->update(
            [],
            ['$unset' => ['parameters' => $id]], ['multiple' => true]);

Where $id id 592193d6470e6cf80d3c9874.

4
  • $this->collection->update([],['$unset' => ['parameters' => null]], ['multiple' => true]); Commented May 21, 2017 at 14:50
  • $this->collection->update([],['$unset' => ['parameters.'.$parameterId => null]], ['multiple' => true]); .... try Commented May 21, 2017 at 14:53
  • what do you mean by pull ? you want to delete that document ? Commented May 21, 2017 at 15:04
  • It does not work: $this->collection->update([],['$unset' => ['parameters.'.$id => null]], ['multiple' => true]); Commented May 21, 2017 at 16:04

1 Answer 1

1
$this->collection->update(['$unset' => ['parameters'=> ['_id'] => $id], ['multiple' => true]);

or

$this->collection->update(['$unset' => ['parameters.'.$parameterId => null]], ['multiple' => true]);
Sign up to request clarification or add additional context in comments.

6 Comments

Okay man, thank you, can I ask you, how to add in parameters? I tried: $this->collection->update( ["prototype_id" => $id], ['$set' => ["parameters" => array(array($key => $data))]], ["multiple" => true]); It overwrites all parameters
And does not work you sample, cause parameters is array
$this->collection->update(['$unset' => ['parameters'=> ['_id'] => $id], ['multiple' => true]);
Can you give me your private contact?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.