FAQ
Hello Everyone,

I needed some help to create a count query on nested objects in a field,
across all documents. Each document json has a many fields. One particular
field called "hotlinks" comprises of many internal dynamic object fields.
Doc1:
{
   hotlinks : { 112222:{....} , 333333: {.....} , 545555: {.....} }
}

Doc2:
{
   hotlinks : { 67756:{....} , 756767: {.....} , 1111111: {.....} }
}

Each document has a hotlinks fields. The hotlinks field comprises of varied
inner hotlink objects. Each key is a java unique id and has objects that
contain data (inner fields)
I needed a way to get the count of all the inner nested objects of the
field – ‘hotlinks’.
For example the summation of inner objects of hotlinks in doc1 and doc2
would be 6.
Is there any way to do this via a single query to get the count across all
documents.

Thanks a lot,
Karan

--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user+unsubscribe@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Karan at Aug 12, 2013 at 9:06 pm
    Hello Everyone,

    I needed some help to create a count query on nested objects in a field,
    across all documents. Each document json has a many fields. One particular
    field called "hotlinks" comprises of many internal dynamic object fields.
    Doc1:
    {
       hotlinks : { 112222:{....} , 333333: {.....} , 545555: {.....} }
    }

    Doc2:
    {
       hotlinks : { 67756:{....} , 756767: {.....} , 1111111: {.....} }
    }

    Each document has a hotlinks fields. The hotlinks field comprises of varied
    inner hotlink objects. Each key is a java unique id and has objects that
    contain data (inner fields)
    I needed a way to get the count of all the inner nested objects of the
    field – ‘hotlinks’.
    For example the summation of inner objects of hotlinks in doc1 and doc2
    would be 6.
    Is there any way to do this via a single query to get the count across all
    documents.

    Thanks a lot,
    Karan

    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Gary R at Aug 13, 2013 at 5:45 pm
    A few thoughts.

        - This would work nicely in the aggregation framework if the 'hotlinks
        fields" would be elements in an array instead of a document.
        - Or, you could easy maintain a counter as hotlinks are added and
        removed and just read this.
        - Or, in map-reduce, javascript could include the idea: for(k in obj)
        {count++;}

    Gary R.

    --------------------------------

    On Monday, August 12, 2013 3:51:45 AM UTC-6, Karan wrote:

    Hello Everyone,

    I needed some help to create a count query on nested objects in a field,
    across all documents. Each document json has a many fields. One particular
    field called "hotlinks" comprises of many internal dynamic object fields.
    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Karan at Aug 14, 2013 at 9:21 am
    Hi Gary,

    Thank you so much. All the ideas you gave are great.
    For now, i have implemented the second option that you have suggested-
    Maintain a counter.
    This is now working for me.

    Thanks so much,
    Karan
    On Tuesday, August 13, 2013 11:15:08 PM UTC+5:30, Gary R wrote:

    A few thoughts.

    - This would work nicely in the aggregation framework if the 'hotlinks
    fields" would be elements in an array instead of a document.
    - Or, you could easy maintain a counter as hotlinks are added and
    removed and just read this.
    - Or, in map-reduce, javascript could include the idea: for(k in obj)
    {count++;}

    Gary R.

    --------------------------------

    On Monday, August 12, 2013 3:51:45 AM UTC-6, Karan wrote:

    Hello Everyone,

    I needed some help to create a count query on nested objects in a field,
    across all documents. Each document json has a many fields. One particular
    field called "hotlinks" comprises of many internal dynamic object fields.
    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmongodb-user @
categoriesmongodb
postedAug 12, '13 at 9:06p
activeAug 14, '13 at 9:21a
posts4
users2
websitemongodb.org
irc#mongodb

2 users in discussion

Karan: 3 posts Gary R: 1 post

People

Translate

site design / logo © 2022 Grokbase