get inner child array content as query result in mongodbHow to query MongoDB with “like”?Retrieve only the queried element in an object array in MongoDB collectionHow to get the last N records in mongodb?Query for documents where array size is greater than 1Find MongoDB records where array field is not emptyWhy is the result of a reduce function fed back into reduce using mongodb mapreducecomparing a string field to a sub-array field in mongodbMongodb Map Reduce: How can I group the result?Count of inner parent and inner arrays - MongodbInner array total count in mongodb

Why are only specific transaction types accepted into the mempool?

TGV timetables / schedules?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

New order #4: World

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

How old can references or sources in a thesis be?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Why don't electron-positron collisions release infinite energy?

Schwarzchild Radius of the Universe

Why CLRS example on residual networks does not follows its formula?

Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?

Circuitry of TV splitters

Download, install and reboot computer at night if needed

Copenhagen passport control - US citizen

I probably found a bug with the sudo apt install function

How to add power-LED to my small amplifier?

Motorized valve interfering with button?

Is there really no realistic way for a skeleton monster to move around without magic?

What are these boxed doors outside store fronts in New York?

Why has Russell's definition of numbers using equivalence classes been finally abandoned? ( If it has actually been abandoned).

Chess with symmetric move-square

Can I make popcorn with any corn?

Patience, young "Padovan"

Can Medicine checks be used, with decent rolls, to completely mitigate the risk of death from ongoing damage?



get inner child array content as query result in mongodb


How to query MongoDB with “like”?Retrieve only the queried element in an object array in MongoDB collectionHow to get the last N records in mongodb?Query for documents where array size is greater than 1Find MongoDB records where array field is not emptyWhy is the result of a reduce function fed back into reduce using mongodb mapreducecomparing a string field to a sub-array field in mongodbMongodb Map Reduce: How can I group the result?Count of inner parent and inner arrays - MongodbInner array total count in mongodb






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








0















I have a journal collection contains journal details, volumes, issues and articles. I need to get the issue name and the article count in it from the below collection. Condition will be :



_id = ObjectId("5c7faf8384bbfc127f171222")



jnl_volumes.name = 1




Here is my doc:




"_id":ObjectId("5c7faf8384bbfc127f171222"),
"jnl_code":"QWER",
"jnl_title":"Title",
"jnl_short_title":"short",
"jnl_accronym":"accronym",
"jnl_issn":"issn",
"jnl_eissn":"eissn",
"jnl_license_type":
"name":"Open access",
"value":"o"
,
"jnl_category":
"name":"Science",
"value":"s"
,
"jnl_volumes":[

"name":1,
"created_date":"2019-03-06",
"status":"0",
"issue_flag":"0",
"jnl_issues":[

"issue_name":"2",
"created_date":"2019-03-07",
"jnl_articles":[
"ART 1",
"ART 2"
]
,

"issue_name":"3",
"created_date":"2019-03-07",
"jnl_articles":[
"A 1"
]
,

"issue_name":"4",
"created_date":"2019-03-07",
"jnl_articles":[
"AR 1"
]

]
,

"name":2,
"created_date":"2019-03-06",
"status":"0",
"issue_flag":"0",
"jnl_issues":[

"issue_name":"1",
"created_date":"2019-03-07",
"jnl_articles":[
"Article 1",
"Article 2",
"Article 3",
"Article 4",
"Article 5"
]

]

],
"jnl_created_by":"1",
"jnl_status":"a",
"jnl_proxy_id":"0",
"jnl_operation":"i",
"jnl_updated_date":ISODate("2019-03-07T11:05:21.000Z"),
"jnl_created_date":ISODate("2019-03-07T11:05:21.000Z")



I want the result contain jnl_issues.name and the count of jnl_articles in it....










share|improve this question
























  • Do you want the mongodb command or the mongoose command?

    – Black-Hole
    Mar 8 at 6:18











  • @Black-Hole Mongodb please...

    – Anoop Sankar
    Mar 8 at 7:02

















0















I have a journal collection contains journal details, volumes, issues and articles. I need to get the issue name and the article count in it from the below collection. Condition will be :



_id = ObjectId("5c7faf8384bbfc127f171222")



jnl_volumes.name = 1




Here is my doc:




"_id":ObjectId("5c7faf8384bbfc127f171222"),
"jnl_code":"QWER",
"jnl_title":"Title",
"jnl_short_title":"short",
"jnl_accronym":"accronym",
"jnl_issn":"issn",
"jnl_eissn":"eissn",
"jnl_license_type":
"name":"Open access",
"value":"o"
,
"jnl_category":
"name":"Science",
"value":"s"
,
"jnl_volumes":[

"name":1,
"created_date":"2019-03-06",
"status":"0",
"issue_flag":"0",
"jnl_issues":[

"issue_name":"2",
"created_date":"2019-03-07",
"jnl_articles":[
"ART 1",
"ART 2"
]
,

"issue_name":"3",
"created_date":"2019-03-07",
"jnl_articles":[
"A 1"
]
,

"issue_name":"4",
"created_date":"2019-03-07",
"jnl_articles":[
"AR 1"
]

]
,

"name":2,
"created_date":"2019-03-06",
"status":"0",
"issue_flag":"0",
"jnl_issues":[

"issue_name":"1",
"created_date":"2019-03-07",
"jnl_articles":[
"Article 1",
"Article 2",
"Article 3",
"Article 4",
"Article 5"
]

]

],
"jnl_created_by":"1",
"jnl_status":"a",
"jnl_proxy_id":"0",
"jnl_operation":"i",
"jnl_updated_date":ISODate("2019-03-07T11:05:21.000Z"),
"jnl_created_date":ISODate("2019-03-07T11:05:21.000Z")



I want the result contain jnl_issues.name and the count of jnl_articles in it....










share|improve this question
























  • Do you want the mongodb command or the mongoose command?

    – Black-Hole
    Mar 8 at 6:18











  • @Black-Hole Mongodb please...

    – Anoop Sankar
    Mar 8 at 7:02













0












0








0








I have a journal collection contains journal details, volumes, issues and articles. I need to get the issue name and the article count in it from the below collection. Condition will be :



_id = ObjectId("5c7faf8384bbfc127f171222")



jnl_volumes.name = 1




Here is my doc:




"_id":ObjectId("5c7faf8384bbfc127f171222"),
"jnl_code":"QWER",
"jnl_title":"Title",
"jnl_short_title":"short",
"jnl_accronym":"accronym",
"jnl_issn":"issn",
"jnl_eissn":"eissn",
"jnl_license_type":
"name":"Open access",
"value":"o"
,
"jnl_category":
"name":"Science",
"value":"s"
,
"jnl_volumes":[

"name":1,
"created_date":"2019-03-06",
"status":"0",
"issue_flag":"0",
"jnl_issues":[

"issue_name":"2",
"created_date":"2019-03-07",
"jnl_articles":[
"ART 1",
"ART 2"
]
,

"issue_name":"3",
"created_date":"2019-03-07",
"jnl_articles":[
"A 1"
]
,

"issue_name":"4",
"created_date":"2019-03-07",
"jnl_articles":[
"AR 1"
]

]
,

"name":2,
"created_date":"2019-03-06",
"status":"0",
"issue_flag":"0",
"jnl_issues":[

"issue_name":"1",
"created_date":"2019-03-07",
"jnl_articles":[
"Article 1",
"Article 2",
"Article 3",
"Article 4",
"Article 5"
]

]

],
"jnl_created_by":"1",
"jnl_status":"a",
"jnl_proxy_id":"0",
"jnl_operation":"i",
"jnl_updated_date":ISODate("2019-03-07T11:05:21.000Z"),
"jnl_created_date":ISODate("2019-03-07T11:05:21.000Z")



I want the result contain jnl_issues.name and the count of jnl_articles in it....










share|improve this question
















I have a journal collection contains journal details, volumes, issues and articles. I need to get the issue name and the article count in it from the below collection. Condition will be :



_id = ObjectId("5c7faf8384bbfc127f171222")



jnl_volumes.name = 1




Here is my doc:




"_id":ObjectId("5c7faf8384bbfc127f171222"),
"jnl_code":"QWER",
"jnl_title":"Title",
"jnl_short_title":"short",
"jnl_accronym":"accronym",
"jnl_issn":"issn",
"jnl_eissn":"eissn",
"jnl_license_type":
"name":"Open access",
"value":"o"
,
"jnl_category":
"name":"Science",
"value":"s"
,
"jnl_volumes":[

"name":1,
"created_date":"2019-03-06",
"status":"0",
"issue_flag":"0",
"jnl_issues":[

"issue_name":"2",
"created_date":"2019-03-07",
"jnl_articles":[
"ART 1",
"ART 2"
]
,

"issue_name":"3",
"created_date":"2019-03-07",
"jnl_articles":[
"A 1"
]
,

"issue_name":"4",
"created_date":"2019-03-07",
"jnl_articles":[
"AR 1"
]

]
,

"name":2,
"created_date":"2019-03-06",
"status":"0",
"issue_flag":"0",
"jnl_issues":[

"issue_name":"1",
"created_date":"2019-03-07",
"jnl_articles":[
"Article 1",
"Article 2",
"Article 3",
"Article 4",
"Article 5"
]

]

],
"jnl_created_by":"1",
"jnl_status":"a",
"jnl_proxy_id":"0",
"jnl_operation":"i",
"jnl_updated_date":ISODate("2019-03-07T11:05:21.000Z"),
"jnl_created_date":ISODate("2019-03-07T11:05:21.000Z")



I want the result contain jnl_issues.name and the count of jnl_articles in it....







mongodb mongoose






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 7:02









Black-Hole

287110




287110










asked Mar 8 at 6:06









Anoop SankarAnoop Sankar

436




436












  • Do you want the mongodb command or the mongoose command?

    – Black-Hole
    Mar 8 at 6:18











  • @Black-Hole Mongodb please...

    – Anoop Sankar
    Mar 8 at 7:02

















  • Do you want the mongodb command or the mongoose command?

    – Black-Hole
    Mar 8 at 6:18











  • @Black-Hole Mongodb please...

    – Anoop Sankar
    Mar 8 at 7:02
















Do you want the mongodb command or the mongoose command?

– Black-Hole
Mar 8 at 6:18





Do you want the mongodb command or the mongoose command?

– Black-Hole
Mar 8 at 6:18













@Black-Hole Mongodb please...

– Anoop Sankar
Mar 8 at 7:02





@Black-Hole Mongodb please...

– Anoop Sankar
Mar 8 at 7:02












1 Answer
1






active

oldest

votes


















0














The following is the result of using mongodb's aggregation, there may be room for optimization, but I still don't know how to optimize it.



db.test.aggregate([
$match: '_id': ObjectId("5c7faf8384bbfc127f171222") ,
$project: 'jnl_volumes': 1 ,
$unwind: '$jnl_volumes' ,
$match: 'jnl_volumes.name': 1 ,
$group: '_id': null, 'info': $push: '$jnl_volumes.jnl_issues' ,
$unwind: '$info' ,
$unwind: '$info' ,
$project: 'name': '$info.issue_name', 'count': $sum: $size: '$info.jnl_articles'
])


This is my result:



enter image description here






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%2f55057609%2fget-inner-child-array-content-as-query-result-in-mongodb%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The following is the result of using mongodb's aggregation, there may be room for optimization, but I still don't know how to optimize it.



    db.test.aggregate([
    $match: '_id': ObjectId("5c7faf8384bbfc127f171222") ,
    $project: 'jnl_volumes': 1 ,
    $unwind: '$jnl_volumes' ,
    $match: 'jnl_volumes.name': 1 ,
    $group: '_id': null, 'info': $push: '$jnl_volumes.jnl_issues' ,
    $unwind: '$info' ,
    $unwind: '$info' ,
    $project: 'name': '$info.issue_name', 'count': $sum: $size: '$info.jnl_articles'
    ])


    This is my result:



    enter image description here






    share|improve this answer



























      0














      The following is the result of using mongodb's aggregation, there may be room for optimization, but I still don't know how to optimize it.



      db.test.aggregate([
      $match: '_id': ObjectId("5c7faf8384bbfc127f171222") ,
      $project: 'jnl_volumes': 1 ,
      $unwind: '$jnl_volumes' ,
      $match: 'jnl_volumes.name': 1 ,
      $group: '_id': null, 'info': $push: '$jnl_volumes.jnl_issues' ,
      $unwind: '$info' ,
      $unwind: '$info' ,
      $project: 'name': '$info.issue_name', 'count': $sum: $size: '$info.jnl_articles'
      ])


      This is my result:



      enter image description here






      share|improve this answer

























        0












        0








        0







        The following is the result of using mongodb's aggregation, there may be room for optimization, but I still don't know how to optimize it.



        db.test.aggregate([
        $match: '_id': ObjectId("5c7faf8384bbfc127f171222") ,
        $project: 'jnl_volumes': 1 ,
        $unwind: '$jnl_volumes' ,
        $match: 'jnl_volumes.name': 1 ,
        $group: '_id': null, 'info': $push: '$jnl_volumes.jnl_issues' ,
        $unwind: '$info' ,
        $unwind: '$info' ,
        $project: 'name': '$info.issue_name', 'count': $sum: $size: '$info.jnl_articles'
        ])


        This is my result:



        enter image description here






        share|improve this answer













        The following is the result of using mongodb's aggregation, there may be room for optimization, but I still don't know how to optimize it.



        db.test.aggregate([
        $match: '_id': ObjectId("5c7faf8384bbfc127f171222") ,
        $project: 'jnl_volumes': 1 ,
        $unwind: '$jnl_volumes' ,
        $match: 'jnl_volumes.name': 1 ,
        $group: '_id': null, 'info': $push: '$jnl_volumes.jnl_issues' ,
        $unwind: '$info' ,
        $unwind: '$info' ,
        $project: 'name': '$info.issue_name', 'count': $sum: $size: '$info.jnl_articles'
        ])


        This is my result:



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 7:56









        Black-HoleBlack-Hole

        287110




        287110





























            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%2f55057609%2fget-inner-child-array-content-as-query-result-in-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

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко