Find in Double Nested Array MongoDB Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!MongoDB find value match for a property in array within array of objectsmongoose find by nested object ids return the entire documentFilter nested array in mongodb?How to Query for Embedded document in MongoDb?find in nested array pymongopython3 pymongo find and array_filtersMongoDB: Filtering a double nested array by list membershipGet exactly one object from 3 level nested schema in mongoDBmongodb filter on array inside arrayMongoDB queries on embedded documents within arrays not returning results

/bin/ls sorts differently than just ls

Suing a Police Officer Instead of the Police Department

Marquee sign letters

Why do C and C++ allow the expression (int) + 4*5?

Why aren't these two solutions equivalent? Combinatorics problem

When does Bran Stark remember Jamie pushing him?

What's the connection between Mr. Nancy and fried chicken?

Coin Game with infinite paradox

What were wait-states, and why was it only an issue for PCs?

Why do people think Winterfell crypts is the safest place for women, children & old people?

Is "ein Herz wie das meine" an antiquated or colloquial use of the possesive pronoun?

Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?

Can I ask an author to send me his ebook?

Why aren't road bike wheels tiny?

2 sample t test for sample sizes - 30,000 and 150,000

What is the difference between 准时 and 按时?

How is an IPA symbol that lacks a name (e.g. ɲ) called?

Is my guitar’s action too high?

How do I deal with an erroneously large refund?

Why is one lightbulb in a string illuminated?

Is Bran literally the world's memory?

Why these surprising proportionalities of integrals involving odd zeta values?

What's the difference between using dependency injection with a container and using a service locator?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?



Find in Double Nested Array MongoDB



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!MongoDB find value match for a property in array within array of objectsmongoose find by nested object ids return the entire documentFilter nested array in mongodb?How to Query for Embedded document in MongoDb?find in nested array pymongopython3 pymongo find and array_filtersMongoDB: Filtering a double nested array by list membershipGet exactly one object from 3 level nested schema in mongoDBmongodb filter on array inside arrayMongoDB queries on embedded documents within arrays not returning results



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








14















I have this Collection in mongodb




"_id" : "777",
"someKey" : "someValue",
"someArray" : [

"name" : "name1",
"someNestedArray" : [

"name" : "value"
,

"name" : "delete me"

]

]



I want to find document based on someArray.someNestedArray.name
but i can't find any useful link all search result about update nested array
i am trying this but return nothing



db.mycollection.find("someArray.$.someNestedArray":"$elemMatch":"name":"1")
db.mycollection.find("someArray.$.someNestedArray.$.name":"1")


and Some thing else



how can i find by element in double nested array mongodb?










share|improve this question






























    14















    I have this Collection in mongodb




    "_id" : "777",
    "someKey" : "someValue",
    "someArray" : [

    "name" : "name1",
    "someNestedArray" : [

    "name" : "value"
    ,

    "name" : "delete me"

    ]

    ]



    I want to find document based on someArray.someNestedArray.name
    but i can't find any useful link all search result about update nested array
    i am trying this but return nothing



    db.mycollection.find("someArray.$.someNestedArray":"$elemMatch":"name":"1")
    db.mycollection.find("someArray.$.someNestedArray.$.name":"1")


    and Some thing else



    how can i find by element in double nested array mongodb?










    share|improve this question


























      14












      14








      14


      9






      I have this Collection in mongodb




      "_id" : "777",
      "someKey" : "someValue",
      "someArray" : [

      "name" : "name1",
      "someNestedArray" : [

      "name" : "value"
      ,

      "name" : "delete me"

      ]

      ]



      I want to find document based on someArray.someNestedArray.name
      but i can't find any useful link all search result about update nested array
      i am trying this but return nothing



      db.mycollection.find("someArray.$.someNestedArray":"$elemMatch":"name":"1")
      db.mycollection.find("someArray.$.someNestedArray.$.name":"1")


      and Some thing else



      how can i find by element in double nested array mongodb?










      share|improve this question
















      I have this Collection in mongodb




      "_id" : "777",
      "someKey" : "someValue",
      "someArray" : [

      "name" : "name1",
      "someNestedArray" : [

      "name" : "value"
      ,

      "name" : "delete me"

      ]

      ]



      I want to find document based on someArray.someNestedArray.name
      but i can't find any useful link all search result about update nested array
      i am trying this but return nothing



      db.mycollection.find("someArray.$.someNestedArray":"$elemMatch":"name":"1")
      db.mycollection.find("someArray.$.someNestedArray.$.name":"1")


      and Some thing else



      how can i find by element in double nested array mongodb?







      mongodb mongodb-query aggregation-framework






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 30 '17 at 9:15









      Neil Lunn

      102k23181189




      102k23181189










      asked Mar 16 '15 at 7:39









      user298582user298582

      3681415




      3681415






















          2 Answers
          2






          active

          oldest

          votes


















          40
















          In the simplest sense this just follows the basic form of "dot notation" as used by MongoDB. That will work regardless of which array member the inner array member is in, as long as it matches a value:



          db.mycollection.find(
          "someArray.someNestedArray.name": "value"
          )


          That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch:



          db.mycollection.find(
          "someArray":
          "$elemMatch":
          "name": "name1",
          "someNestedArray":
          "$elemMatch":
          "name": "value",
          "otherField": 1




          )


          That matches the document which would contain something with a a field at that "path" matching the value. If you intended to "match and filter" the result so only the matched element was returned, this is not possible with the positional operator projection, as quoted:




          Nested Arrays



          The positional $ operator cannot be used for queries which traverse more than one array, such as queries that traverse arrays nested within other arrays, because the replacement for the $ placeholder is a single value




          Modern MongoDB



          We can do this by applying $filter and $map here. The $map is really needed because the "inner" array can change as a result of the "filtering", and the "outer" array of course does not match the conditions when the "inner" was stripped of all elements.



          Again following the example of actually having multiple properties to match within each array:



          db.mycollection.aggregate([
          "$match":
          "someArray":
          "$elemMatch":
          "name": "name1",
          "someNestedArray":
          "$elemMatch":
          "name": "value",
          "otherField": 1




          ,
          "$addFields":
          "someArray":
          "$filter":
          "input":
          "$map":
          "input": "$someArray",
          "as": "sa",
          "in":
          "name": "$$sa.name",
          "someNestedArray":
          "$filter":
          "input": "$$sa.someNestedArray",
          "as": "sn",
          "cond":
          "$and": [
          "$eq": [ "$$sn.name", "value" ] ,
          "$eq": [ "$$sn.otherField", 1 ]
          ]




          ,
          ,
          "as": "sa",
          "cond":
          "$and": [
          "$eq": [ "$$sa.name", "name1" ] ,
          "$gt": [ "$size": "$$sa.someNestedArray" , 0 ]
          ]




          ])


          Therefore on the "outer" array the $filter actually looks at the $size of the "inner" array after it was "filtered" itself, so you can reject those results when the whole inner array does in fact match noting.



          Older MongoDB



          In order to "project" only the matched element, you need the .aggregate() method:



          db.mycollection.aggregate([
          // Match possible documents
          "$match":
          "someArray.someNestedArray.name": "value"
          ,

          // Unwind each array
          "$unwind": "$someArray" ,
          "$unwind": "$someArray.someNestedArray" ,

          // Filter just the matching elements
          "$match":
          "someArray.someNestedArray.name": "value"
          ,

          // Group to inner array
          "$group":
          "_id":
          "_id": "$_id",
          "name": "$someArray.name"
          ,
          "someKey": "$first": "$someKey" ,
          "someNestedArray": "$push": "$someArray.someNestedArray"
          ,

          // Group to outer array
          "$group":
          "_id": "$_id._id",
          "someKey": "$first": "$someKey" ,
          "someArray": "$push":
          "name": "$_id.name",
          "someNestedArray": "$someNestedArray"


          ])


          That allows you to "filter" the matches in nested arrays for one or more results within the document.






          share|improve this answer

























          • Thanks, That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch this line clarified me the exact use of elemMatch,

            – Sravan
            Oct 10 '17 at 11:26



















          0














          You can also try something like below:



          db.collection.aggregate(
          $unwind: '$someArray' ,

          $project:
          'filteredValue':
          $filter:
          input: "$someArray.someNestedArray",
          as: "someObj",
          cond: $eq: [ '$$someObj.name', 'delete me' ]




          )





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29071748%2ffind-in-double-nested-array-mongodb%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            40
















            In the simplest sense this just follows the basic form of "dot notation" as used by MongoDB. That will work regardless of which array member the inner array member is in, as long as it matches a value:



            db.mycollection.find(
            "someArray.someNestedArray.name": "value"
            )


            That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch:



            db.mycollection.find(
            "someArray":
            "$elemMatch":
            "name": "name1",
            "someNestedArray":
            "$elemMatch":
            "name": "value",
            "otherField": 1




            )


            That matches the document which would contain something with a a field at that "path" matching the value. If you intended to "match and filter" the result so only the matched element was returned, this is not possible with the positional operator projection, as quoted:




            Nested Arrays



            The positional $ operator cannot be used for queries which traverse more than one array, such as queries that traverse arrays nested within other arrays, because the replacement for the $ placeholder is a single value




            Modern MongoDB



            We can do this by applying $filter and $map here. The $map is really needed because the "inner" array can change as a result of the "filtering", and the "outer" array of course does not match the conditions when the "inner" was stripped of all elements.



            Again following the example of actually having multiple properties to match within each array:



            db.mycollection.aggregate([
            "$match":
            "someArray":
            "$elemMatch":
            "name": "name1",
            "someNestedArray":
            "$elemMatch":
            "name": "value",
            "otherField": 1




            ,
            "$addFields":
            "someArray":
            "$filter":
            "input":
            "$map":
            "input": "$someArray",
            "as": "sa",
            "in":
            "name": "$$sa.name",
            "someNestedArray":
            "$filter":
            "input": "$$sa.someNestedArray",
            "as": "sn",
            "cond":
            "$and": [
            "$eq": [ "$$sn.name", "value" ] ,
            "$eq": [ "$$sn.otherField", 1 ]
            ]




            ,
            ,
            "as": "sa",
            "cond":
            "$and": [
            "$eq": [ "$$sa.name", "name1" ] ,
            "$gt": [ "$size": "$$sa.someNestedArray" , 0 ]
            ]




            ])


            Therefore on the "outer" array the $filter actually looks at the $size of the "inner" array after it was "filtered" itself, so you can reject those results when the whole inner array does in fact match noting.



            Older MongoDB



            In order to "project" only the matched element, you need the .aggregate() method:



            db.mycollection.aggregate([
            // Match possible documents
            "$match":
            "someArray.someNestedArray.name": "value"
            ,

            // Unwind each array
            "$unwind": "$someArray" ,
            "$unwind": "$someArray.someNestedArray" ,

            // Filter just the matching elements
            "$match":
            "someArray.someNestedArray.name": "value"
            ,

            // Group to inner array
            "$group":
            "_id":
            "_id": "$_id",
            "name": "$someArray.name"
            ,
            "someKey": "$first": "$someKey" ,
            "someNestedArray": "$push": "$someArray.someNestedArray"
            ,

            // Group to outer array
            "$group":
            "_id": "$_id._id",
            "someKey": "$first": "$someKey" ,
            "someArray": "$push":
            "name": "$_id.name",
            "someNestedArray": "$someNestedArray"


            ])


            That allows you to "filter" the matches in nested arrays for one or more results within the document.






            share|improve this answer

























            • Thanks, That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch this line clarified me the exact use of elemMatch,

              – Sravan
              Oct 10 '17 at 11:26
















            40
















            In the simplest sense this just follows the basic form of "dot notation" as used by MongoDB. That will work regardless of which array member the inner array member is in, as long as it matches a value:



            db.mycollection.find(
            "someArray.someNestedArray.name": "value"
            )


            That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch:



            db.mycollection.find(
            "someArray":
            "$elemMatch":
            "name": "name1",
            "someNestedArray":
            "$elemMatch":
            "name": "value",
            "otherField": 1




            )


            That matches the document which would contain something with a a field at that "path" matching the value. If you intended to "match and filter" the result so only the matched element was returned, this is not possible with the positional operator projection, as quoted:




            Nested Arrays



            The positional $ operator cannot be used for queries which traverse more than one array, such as queries that traverse arrays nested within other arrays, because the replacement for the $ placeholder is a single value




            Modern MongoDB



            We can do this by applying $filter and $map here. The $map is really needed because the "inner" array can change as a result of the "filtering", and the "outer" array of course does not match the conditions when the "inner" was stripped of all elements.



            Again following the example of actually having multiple properties to match within each array:



            db.mycollection.aggregate([
            "$match":
            "someArray":
            "$elemMatch":
            "name": "name1",
            "someNestedArray":
            "$elemMatch":
            "name": "value",
            "otherField": 1




            ,
            "$addFields":
            "someArray":
            "$filter":
            "input":
            "$map":
            "input": "$someArray",
            "as": "sa",
            "in":
            "name": "$$sa.name",
            "someNestedArray":
            "$filter":
            "input": "$$sa.someNestedArray",
            "as": "sn",
            "cond":
            "$and": [
            "$eq": [ "$$sn.name", "value" ] ,
            "$eq": [ "$$sn.otherField", 1 ]
            ]




            ,
            ,
            "as": "sa",
            "cond":
            "$and": [
            "$eq": [ "$$sa.name", "name1" ] ,
            "$gt": [ "$size": "$$sa.someNestedArray" , 0 ]
            ]




            ])


            Therefore on the "outer" array the $filter actually looks at the $size of the "inner" array after it was "filtered" itself, so you can reject those results when the whole inner array does in fact match noting.



            Older MongoDB



            In order to "project" only the matched element, you need the .aggregate() method:



            db.mycollection.aggregate([
            // Match possible documents
            "$match":
            "someArray.someNestedArray.name": "value"
            ,

            // Unwind each array
            "$unwind": "$someArray" ,
            "$unwind": "$someArray.someNestedArray" ,

            // Filter just the matching elements
            "$match":
            "someArray.someNestedArray.name": "value"
            ,

            // Group to inner array
            "$group":
            "_id":
            "_id": "$_id",
            "name": "$someArray.name"
            ,
            "someKey": "$first": "$someKey" ,
            "someNestedArray": "$push": "$someArray.someNestedArray"
            ,

            // Group to outer array
            "$group":
            "_id": "$_id._id",
            "someKey": "$first": "$someKey" ,
            "someArray": "$push":
            "name": "$_id.name",
            "someNestedArray": "$someNestedArray"


            ])


            That allows you to "filter" the matches in nested arrays for one or more results within the document.






            share|improve this answer

























            • Thanks, That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch this line clarified me the exact use of elemMatch,

              – Sravan
              Oct 10 '17 at 11:26














            40












            40








            40









            In the simplest sense this just follows the basic form of "dot notation" as used by MongoDB. That will work regardless of which array member the inner array member is in, as long as it matches a value:



            db.mycollection.find(
            "someArray.someNestedArray.name": "value"
            )


            That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch:



            db.mycollection.find(
            "someArray":
            "$elemMatch":
            "name": "name1",
            "someNestedArray":
            "$elemMatch":
            "name": "value",
            "otherField": 1




            )


            That matches the document which would contain something with a a field at that "path" matching the value. If you intended to "match and filter" the result so only the matched element was returned, this is not possible with the positional operator projection, as quoted:




            Nested Arrays



            The positional $ operator cannot be used for queries which traverse more than one array, such as queries that traverse arrays nested within other arrays, because the replacement for the $ placeholder is a single value




            Modern MongoDB



            We can do this by applying $filter and $map here. The $map is really needed because the "inner" array can change as a result of the "filtering", and the "outer" array of course does not match the conditions when the "inner" was stripped of all elements.



            Again following the example of actually having multiple properties to match within each array:



            db.mycollection.aggregate([
            "$match":
            "someArray":
            "$elemMatch":
            "name": "name1",
            "someNestedArray":
            "$elemMatch":
            "name": "value",
            "otherField": 1




            ,
            "$addFields":
            "someArray":
            "$filter":
            "input":
            "$map":
            "input": "$someArray",
            "as": "sa",
            "in":
            "name": "$$sa.name",
            "someNestedArray":
            "$filter":
            "input": "$$sa.someNestedArray",
            "as": "sn",
            "cond":
            "$and": [
            "$eq": [ "$$sn.name", "value" ] ,
            "$eq": [ "$$sn.otherField", 1 ]
            ]




            ,
            ,
            "as": "sa",
            "cond":
            "$and": [
            "$eq": [ "$$sa.name", "name1" ] ,
            "$gt": [ "$size": "$$sa.someNestedArray" , 0 ]
            ]




            ])


            Therefore on the "outer" array the $filter actually looks at the $size of the "inner" array after it was "filtered" itself, so you can reject those results when the whole inner array does in fact match noting.



            Older MongoDB



            In order to "project" only the matched element, you need the .aggregate() method:



            db.mycollection.aggregate([
            // Match possible documents
            "$match":
            "someArray.someNestedArray.name": "value"
            ,

            // Unwind each array
            "$unwind": "$someArray" ,
            "$unwind": "$someArray.someNestedArray" ,

            // Filter just the matching elements
            "$match":
            "someArray.someNestedArray.name": "value"
            ,

            // Group to inner array
            "$group":
            "_id":
            "_id": "$_id",
            "name": "$someArray.name"
            ,
            "someKey": "$first": "$someKey" ,
            "someNestedArray": "$push": "$someArray.someNestedArray"
            ,

            // Group to outer array
            "$group":
            "_id": "$_id._id",
            "someKey": "$first": "$someKey" ,
            "someArray": "$push":
            "name": "$_id.name",
            "someNestedArray": "$someNestedArray"


            ])


            That allows you to "filter" the matches in nested arrays for one or more results within the document.






            share|improve this answer

















            In the simplest sense this just follows the basic form of "dot notation" as used by MongoDB. That will work regardless of which array member the inner array member is in, as long as it matches a value:



            db.mycollection.find(
            "someArray.someNestedArray.name": "value"
            )


            That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch:



            db.mycollection.find(
            "someArray":
            "$elemMatch":
            "name": "name1",
            "someNestedArray":
            "$elemMatch":
            "name": "value",
            "otherField": 1




            )


            That matches the document which would contain something with a a field at that "path" matching the value. If you intended to "match and filter" the result so only the matched element was returned, this is not possible with the positional operator projection, as quoted:




            Nested Arrays



            The positional $ operator cannot be used for queries which traverse more than one array, such as queries that traverse arrays nested within other arrays, because the replacement for the $ placeholder is a single value




            Modern MongoDB



            We can do this by applying $filter and $map here. The $map is really needed because the "inner" array can change as a result of the "filtering", and the "outer" array of course does not match the conditions when the "inner" was stripped of all elements.



            Again following the example of actually having multiple properties to match within each array:



            db.mycollection.aggregate([
            "$match":
            "someArray":
            "$elemMatch":
            "name": "name1",
            "someNestedArray":
            "$elemMatch":
            "name": "value",
            "otherField": 1




            ,
            "$addFields":
            "someArray":
            "$filter":
            "input":
            "$map":
            "input": "$someArray",
            "as": "sa",
            "in":
            "name": "$$sa.name",
            "someNestedArray":
            "$filter":
            "input": "$$sa.someNestedArray",
            "as": "sn",
            "cond":
            "$and": [
            "$eq": [ "$$sn.name", "value" ] ,
            "$eq": [ "$$sn.otherField", 1 ]
            ]




            ,
            ,
            "as": "sa",
            "cond":
            "$and": [
            "$eq": [ "$$sa.name", "name1" ] ,
            "$gt": [ "$size": "$$sa.someNestedArray" , 0 ]
            ]




            ])


            Therefore on the "outer" array the $filter actually looks at the $size of the "inner" array after it was "filtered" itself, so you can reject those results when the whole inner array does in fact match noting.



            Older MongoDB



            In order to "project" only the matched element, you need the .aggregate() method:



            db.mycollection.aggregate([
            // Match possible documents
            "$match":
            "someArray.someNestedArray.name": "value"
            ,

            // Unwind each array
            "$unwind": "$someArray" ,
            "$unwind": "$someArray.someNestedArray" ,

            // Filter just the matching elements
            "$match":
            "someArray.someNestedArray.name": "value"
            ,

            // Group to inner array
            "$group":
            "_id":
            "_id": "$_id",
            "name": "$someArray.name"
            ,
            "someKey": "$first": "$someKey" ,
            "someNestedArray": "$push": "$someArray.someNestedArray"
            ,

            // Group to outer array
            "$group":
            "_id": "$_id._id",
            "someKey": "$first": "$someKey" ,
            "someArray": "$push":
            "name": "$_id.name",
            "someNestedArray": "$someNestedArray"


            ])


            That allows you to "filter" the matches in nested arrays for one or more results within the document.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 30 '17 at 9:15

























            answered Mar 16 '15 at 8:03









            Neil LunnNeil Lunn

            102k23181189




            102k23181189












            • Thanks, That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch this line clarified me the exact use of elemMatch,

              – Sravan
              Oct 10 '17 at 11:26


















            • Thanks, That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch this line clarified me the exact use of elemMatch,

              – Sravan
              Oct 10 '17 at 11:26

















            Thanks, That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch this line clarified me the exact use of elemMatch,

            – Sravan
            Oct 10 '17 at 11:26






            Thanks, That is fine for a "single field" value, for matching multiple-fields you would use $elemMatch this line clarified me the exact use of elemMatch,

            – Sravan
            Oct 10 '17 at 11:26














            0














            You can also try something like below:



            db.collection.aggregate(
            $unwind: '$someArray' ,

            $project:
            'filteredValue':
            $filter:
            input: "$someArray.someNestedArray",
            as: "someObj",
            cond: $eq: [ '$$someObj.name', 'delete me' ]




            )





            share|improve this answer



























              0














              You can also try something like below:



              db.collection.aggregate(
              $unwind: '$someArray' ,

              $project:
              'filteredValue':
              $filter:
              input: "$someArray.someNestedArray",
              as: "someObj",
              cond: $eq: [ '$$someObj.name', 'delete me' ]




              )





              share|improve this answer

























                0












                0








                0







                You can also try something like below:



                db.collection.aggregate(
                $unwind: '$someArray' ,

                $project:
                'filteredValue':
                $filter:
                input: "$someArray.someNestedArray",
                as: "someObj",
                cond: $eq: [ '$$someObj.name', 'delete me' ]




                )





                share|improve this answer













                You can also try something like below:



                db.collection.aggregate(
                $unwind: '$someArray' ,

                $project:
                'filteredValue':
                $filter:
                input: "$someArray.someNestedArray",
                as: "someObj",
                cond: $eq: [ '$$someObj.name', 'delete me' ]




                )






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 18 at 12:19









                JitendraJitendra

                1,3071624




                1,3071624



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29071748%2ffind-in-double-nested-array-mongodb%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved