From 050370281a9349b0375616a9560c9fcb2f849e31 Mon Sep 17 00:00:00 2001 From: ravind Date: Fri, 11 Sep 2015 13:04:19 -0400 Subject: [PATCH] DOCS-4829 Added 'Suppress Specific Fields in Embedded Documents' section with examples DOCS-4829 - changes based on feedback from codereivew fixes to whitespace in code examples DOCS-4829 - Changes per CR22320001, ready for pull --- .../project-fields-from-query-results.txt | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/source/tutorial/project-fields-from-query-results.txt b/source/tutorial/project-fields-from-query-results.txt index 0b2d5e1b45d..fadca8630ae 100644 --- a/source/tutorial/project-fields-from-query-results.txt +++ b/source/tutorial/project-fields-from-query-results.txt @@ -133,6 +133,102 @@ The operation returns the following document: .. code-block:: javascript { "classification" : { "category" : "chocolate" } } + +Suppress Specific Fields in Embedded Documents +---------------------------------------------- + +Use :ref:`dot notation ` to supress specific +fields inside an embedded document using a ``0`` instead of ``1``. +For example, the ``inventory`` collection contains the following document: + +.. code-block:: javascript + + { + "_id" : 3, + "type" : "food", + "item" : "Super Dark Chocolate", + "classification" : { "dept" : "grocery", "category" : "chocolate"}, + "vendor" : { + "primary" : { + "name" : "Marsupial Vending Co", + "address" : "Wallaby Rd", + "delivery" : ["M","W","F"] + }, + "secondary":{ + "name" : "Intl. Chocolatiers", + "address" : "Cocoa Plaza", + "delivery" : ["Sa"] + } + } + } + +The following operation returns all documents where the value of the +``type`` field is ``food`` and the ``_id`` field is ``3``. +The projection supresses only the ``category`` field in the +``classification`` document. The ``dept`` field remains +inside the ``classification`` document. + +.. code-block:: javascript + + db.inventory.find( + { type: 'food', _id: 3 }, + { "classification.category": 0} + ) + +The operation returns the following document: + +.. code-block:: javascript + + { + "_id" : 3, + "type" : "food", + "item" : "Super Dark Chocolate", + "classification" : { "dept" : "grocery"}, + "vendor" : { + "primary" : { + "name" : "Bobs Vending", + "address" : "Wallaby Rd", + "delivery" : ["M","W","F"] + }, + "secondary":{ + "name" : "Intl. Chocolatiers", + "address" : "Cocoa Plaza", + "delivery" : ["Sa"] + } + } + } +You can supress nested subdocuments at any depth using :ref:`dot notation `. +The following specifies a projection to suppress the ``delivery`` array only for the ``secondary`` document. + +.. code-block:: javascript + + db.inventory.find( + { "type" : "food" }, + { "vendor.secondary.delivery" : 0 } + ) + +This returns all documents except the ``delivery`` array in the ``secondary`` document + +.. code-block:: javascript + + { + "_id" : 3, + "type" : "food", + "item" : "Super Dark Chocolate", + "classification" : { "dept" : "grocery", "category" : "chocolate"}, + "vendor" : { + "primary" : { + "name" : "Bobs Vending", + "address" : "Wallaby Rd", + "delivery" : ["M","W","F"] + }, + "secondary":{ + "name" : "Intl. Chocolatiers", + "address" : "Cocoa Plaza" + } + } + } + Projection for Array Fields ---------------------------