mongoengine get value on nested field [duplicate]










0
















This question is an exact duplicate of:



  • mongoengine - Query on ListField of EmbeddedDocumentField

    1 answer



I have following list in mongodb.



> db.article.find().pretty()

"_id" : ObjectId("5bebcfbb1b48d9974aac78ee"),
"no" : 40,
"subject" : "string",
"content" : "string",
"userid" : "string",
"comments" : [

"no" : 1,
"content" : "First content",
"userid" : "john",
"parent" : null,
"seq" : 12,
"created_at" : ISODate("2018-11-14T16:33:01.943Z")
,

"no" : 2,
"content" : "Second",
"userid" : "doe",
"parent" : null,
"seq" : 25,
"created_at" : ISODate("2018-11-14T16:33:01.943Z")
,



Now I'm using mongoengine in my python app.



If I want to get comments's no: 2's seq field value(in this code, it is 25), how can I manipulate my query?



I found the docs related it(http://docs.mongoengine.org/guide/querying.html) But I don't know it is exactly same with what I want.



Any solution here?



Thanks!










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 14 '18 at 8:19


This question was marked as an exact duplicate of an existing question.






















    0
















    This question is an exact duplicate of:



    • mongoengine - Query on ListField of EmbeddedDocumentField

      1 answer



    I have following list in mongodb.



    > db.article.find().pretty()

    "_id" : ObjectId("5bebcfbb1b48d9974aac78ee"),
    "no" : 40,
    "subject" : "string",
    "content" : "string",
    "userid" : "string",
    "comments" : [

    "no" : 1,
    "content" : "First content",
    "userid" : "john",
    "parent" : null,
    "seq" : 12,
    "created_at" : ISODate("2018-11-14T16:33:01.943Z")
    ,

    "no" : 2,
    "content" : "Second",
    "userid" : "doe",
    "parent" : null,
    "seq" : 25,
    "created_at" : ISODate("2018-11-14T16:33:01.943Z")
    ,



    Now I'm using mongoengine in my python app.



    If I want to get comments's no: 2's seq field value(in this code, it is 25), how can I manipulate my query?



    I found the docs related it(http://docs.mongoengine.org/guide/querying.html) But I don't know it is exactly same with what I want.



    Any solution here?



    Thanks!










    share|improve this question













    marked as duplicate by Neil Lunn mongodb
    Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Nov 14 '18 at 8:19


    This question was marked as an exact duplicate of an existing question.




















      0












      0








      0









      This question is an exact duplicate of:



      • mongoengine - Query on ListField of EmbeddedDocumentField

        1 answer



      I have following list in mongodb.



      > db.article.find().pretty()

      "_id" : ObjectId("5bebcfbb1b48d9974aac78ee"),
      "no" : 40,
      "subject" : "string",
      "content" : "string",
      "userid" : "string",
      "comments" : [

      "no" : 1,
      "content" : "First content",
      "userid" : "john",
      "parent" : null,
      "seq" : 12,
      "created_at" : ISODate("2018-11-14T16:33:01.943Z")
      ,

      "no" : 2,
      "content" : "Second",
      "userid" : "doe",
      "parent" : null,
      "seq" : 25,
      "created_at" : ISODate("2018-11-14T16:33:01.943Z")
      ,



      Now I'm using mongoengine in my python app.



      If I want to get comments's no: 2's seq field value(in this code, it is 25), how can I manipulate my query?



      I found the docs related it(http://docs.mongoengine.org/guide/querying.html) But I don't know it is exactly same with what I want.



      Any solution here?



      Thanks!










      share|improve this question















      This question is an exact duplicate of:



      • mongoengine - Query on ListField of EmbeddedDocumentField

        1 answer



      I have following list in mongodb.



      > db.article.find().pretty()

      "_id" : ObjectId("5bebcfbb1b48d9974aac78ee"),
      "no" : 40,
      "subject" : "string",
      "content" : "string",
      "userid" : "string",
      "comments" : [

      "no" : 1,
      "content" : "First content",
      "userid" : "john",
      "parent" : null,
      "seq" : 12,
      "created_at" : ISODate("2018-11-14T16:33:01.943Z")
      ,

      "no" : 2,
      "content" : "Second",
      "userid" : "doe",
      "parent" : null,
      "seq" : 25,
      "created_at" : ISODate("2018-11-14T16:33:01.943Z")
      ,



      Now I'm using mongoengine in my python app.



      If I want to get comments's no: 2's seq field value(in this code, it is 25), how can I manipulate my query?



      I found the docs related it(http://docs.mongoengine.org/guide/querying.html) But I don't know it is exactly same with what I want.



      Any solution here?



      Thanks!





      This question is an exact duplicate of:



      • mongoengine - Query on ListField of EmbeddedDocumentField

        1 answer







      python mongodb mongoengine






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 8:15









      HideHide

      395212




      395212




      marked as duplicate by Neil Lunn mongodb
      Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Nov 14 '18 at 8:19


      This question was marked as an exact duplicate of an existing question.









      marked as duplicate by Neil Lunn mongodb
      Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Nov 14 '18 at 8:19


      This question was marked as an exact duplicate of an existing question.
























          1 Answer
          1






          active

          oldest

          votes


















          1














          db.getCollection('article').aggregate([
          "$project":"comments.seq":1,"comments.no":1,"_id":0,
          "$unwind":"$comments",
          "$match":"comments.no":NumberInt(2),
          "$project":"comments.seq":1
          ])


          enter image description here



          You can refer to it.






          share|improve this answer































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            db.getCollection('article').aggregate([
            "$project":"comments.seq":1,"comments.no":1,"_id":0,
            "$unwind":"$comments",
            "$match":"comments.no":NumberInt(2),
            "$project":"comments.seq":1
            ])


            enter image description here



            You can refer to it.






            share|improve this answer





























              1














              db.getCollection('article').aggregate([
              "$project":"comments.seq":1,"comments.no":1,"_id":0,
              "$unwind":"$comments",
              "$match":"comments.no":NumberInt(2),
              "$project":"comments.seq":1
              ])


              enter image description here



              You can refer to it.






              share|improve this answer



























                1












                1








                1







                db.getCollection('article').aggregate([
                "$project":"comments.seq":1,"comments.no":1,"_id":0,
                "$unwind":"$comments",
                "$match":"comments.no":NumberInt(2),
                "$project":"comments.seq":1
                ])


                enter image description here



                You can refer to it.






                share|improve this answer















                db.getCollection('article').aggregate([
                "$project":"comments.seq":1,"comments.no":1,"_id":0,
                "$unwind":"$comments",
                "$match":"comments.no":NumberInt(2),
                "$project":"comments.seq":1
                ])


                enter image description here



                You can refer to it.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 14 '18 at 8:37









                Unheilig

                12k165387




                12k165387










                answered Nov 14 '18 at 8:32









                KrloyKrloy

                261




                261















                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto