How to unset a field from all documents with php mongo adapter?

Alexandru Olaru

I have the task to $unset some fields from a collection, what i am trying to do :

     $collection->update(
            array(
                'field' => array('$exists' => true),
            ),
            array(
                '$unset' => array(
                    'field' => '',
                )
            ),
            array(
                'multi' => true
            )
        );

In xdebug i am getting: $collection: {w => 1, wtimeout => 10000} but when i check database nothing was changed my field is there untouched.

Alexandru Olaru

Found the issue: Actually the parameter for multi in php is multiple, i didn't count the responses and didn't see that it was unset-ing just one document.

 $collection->update(
        array(
            'field' => array('$exists' => true),
        ),
        array(
            '$unset' => array(
                'field' => '',
            )
        ),
        array(
            'multiple' => true
        )
    );

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Unset many session from application in php but not all

分類Dev

Unset all variables in PHP script

分類Dev

How to get all documents from a collection in FaunaDB?

分類Dev

How can I rename a field for all documents in MongoDB?

分類Dev

How to find all documents where the value of one field matches that of another

分類Dev

How to unset the objects from objects

分類Dev

MongoDB: How to read all documents from all collections use expressjs?

分類Dev

Find all documents in a collection with mongo go driver

分類Dev

Get all documents from mongo collection using a nested list comprehension in Python

分類Dev

Get all documents from mongo collection using a nested list comprehension in Python

分類Dev

How to set and unset relativenumber to all buffers?

分類Dev

How to delete fields from Mongodb (Mongo PHP)?

分類Dev

Mongo aggregation: Count documents based on array field matching condition

分類Dev

How to drop duplicate documents of a sharded indices in mongo?

分類Dev

ElasticSearch - Copy one field value to other field for all documents

分類Dev

Retrieving all documents without iterating the cursor using mongo driver

分類Dev

How to sort documents based on length of an Array field

分類Dev

MongoDB - how to merge dict field of documents?

分類Dev

How do I query a field from Mongo where the value is actually a number but stored as string?

分類Dev

How to get average of one field value per min from mongo with aggregate query?

分類Dev

How to set LiveData from Adapter?

分類Dev

Bulk add new field to ALL documents in an elasticsearch index

分類Dev

Pymongo: Aggregate all documents that not have one field and have another - group by

分類Dev

Removing all documents and collections from the Firestore

分類Dev

Get All 'documents' from MongoDB 'collection'

分類Dev

How to get all documents from a firestore collection and return them in an array list?

分類Dev

On c# how to save all words documents open? (not open from c# )

分類Dev

How to Merge Array and Document Field in Mongo DB

分類Dev

how to sorting according to the value of a field? mongo

Related 関連記事

  1. 1

    Unset many session from application in php but not all

  2. 2

    Unset all variables in PHP script

  3. 3

    How to get all documents from a collection in FaunaDB?

  4. 4

    How can I rename a field for all documents in MongoDB?

  5. 5

    How to find all documents where the value of one field matches that of another

  6. 6

    How to unset the objects from objects

  7. 7

    MongoDB: How to read all documents from all collections use expressjs?

  8. 8

    Find all documents in a collection with mongo go driver

  9. 9

    Get all documents from mongo collection using a nested list comprehension in Python

  10. 10

    Get all documents from mongo collection using a nested list comprehension in Python

  11. 11

    How to set and unset relativenumber to all buffers?

  12. 12

    How to delete fields from Mongodb (Mongo PHP)?

  13. 13

    Mongo aggregation: Count documents based on array field matching condition

  14. 14

    How to drop duplicate documents of a sharded indices in mongo?

  15. 15

    ElasticSearch - Copy one field value to other field for all documents

  16. 16

    Retrieving all documents without iterating the cursor using mongo driver

  17. 17

    How to sort documents based on length of an Array field

  18. 18

    MongoDB - how to merge dict field of documents?

  19. 19

    How do I query a field from Mongo where the value is actually a number but stored as string?

  20. 20

    How to get average of one field value per min from mongo with aggregate query?

  21. 21

    How to set LiveData from Adapter?

  22. 22

    Bulk add new field to ALL documents in an elasticsearch index

  23. 23

    Pymongo: Aggregate all documents that not have one field and have another - group by

  24. 24

    Removing all documents and collections from the Firestore

  25. 25

    Get All 'documents' from MongoDB 'collection'

  26. 26

    How to get all documents from a firestore collection and return them in an array list?

  27. 27

    On c# how to save all words documents open? (not open from c# )

  28. 28

    How to Merge Array and Document Field in Mongo DB

  29. 29

    how to sorting according to the value of a field? mongo

ホットタグ

アーカイブ