Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-5028

Comment on: "about/support.txt"

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Major - P3 Major - P3
    • 01112017-cleanup
    • None
    • None

    Description

      I am practising mongodb in robomongo, I have created document (named "eetusers") with multiple array objects.

      Here is my document:
      db.eetusers.find()

      '/* 0 */
      {
      "_id" : ObjectId("5507c230dea5ce8c8f6a5687"),
      "name" : "Bharat",
      "username" : "pbharatprdxn",
      "email" : "bharat@*.com",
      "vote_details" : [
      {
      "voter_name" : "atul",
      "technical" :

      { "upvote" : 4 }

      ,
      "voted_at" : ISODate("2015-03-17T05:57:04.256Z")
      },
      {
      "voter_name" : "manish",
      "behaviour" :

      { "downvote" : 4 }

      ,
      "voted_at" : ISODate("2015-03-17T05:57:04.256Z")
      }
      ],
      "total_upvotes" : 4,
      "total_downvotes" : 4
      }

      /* 1 */
      {
      "_id" : ObjectId("5507c343dea5ce8c8f6a5688"),
      "name" : "Atul",
      "username" : "natulprdxn",
      "email" : "atul@*.com",
      "vote_details" : [
      {
      "voter_name" : "bharat",
      "technical" :

      { "upvote" : 5 }

      ,
      "voted_at" : ISODate("2015-03-17T06:01:39.845Z")
      },
      {
      "voter_name" : "manish",
      "behaviour" :

      { "downvote" : 3 }

      ,
      "voted_at" : ISODate("2015-03-17T06:01:39.845Z")
      }
      ],
      "total_upvotes" : 5,
      "total_downvotes" : 3
      }

      /* 2 */
      {
      "_id" : ObjectId("5507c35cdea5ce8c8f6a5689"),
      "name" : "Manish",
      "username" : "kmanishprdxn",
      "email" : "manish@*.com",
      "vote_details" : [
      {
      "voter_name" : "bharat",
      "technical" :

      { "upvote" : 5 }

      ,
      "voted_at" : ISODate("2015-03-17T06:02:04.569Z")
      },
      {
      "voter_name" : "atul",
      "behaviour" :

      { "upvote" : 3 }

      ,
      "voted_at" : ISODate("2015-03-17T06:02:04.569Z")
      }
      ],
      "total_upvotes" : 8
      }

      Now, I need to find all the objects in the document satisfying some condition, for that I used the following query:

      db.eetusers.find(
      //Criteria

      { name: 'Parag', 'vote_details.voter_name': 'manish'}

      ,
      {
      vote_details:
      {
      $elemMatch :

      { voter_name: 'manish' }


      }
      }
      )

      but the problem is I am getting only the first object occurence i.e

      /* 0 */
      {
      "_id" : ObjectId("5507e544dea5ce8c8f6a568a"),
      "vote_details" : [
      {
      "voter_name" : "manish",
      "behaviour" :

      { "downvotes" : 4 }

      ,
      "voted_at" : ISODate("2015-04-17T18:30:00.000Z")
      }
      ]
      }

      I want all the occurences of "manish", so can you suggest the proper query to get the desired result?

      Attachments

        Activity

          People

            Unassigned Unassigned
            xgen-internal-docs Docs Collector User (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              7 years, 29 weeks ago