Querying size of an array field

254 views
Skip to first unread message

Ram

unread,
Mar 5, 2012, 8:52:36 PM3/5/12
to mongodb-user
I have a collection called tags with the documents in the below
model.
Each document has a tagname field and mrid field. The mrid field is an
array.


{ "_id" : ObjectId("4f554c9ddc1def1a3a3ba62c"), "tagname" : "sql",
"mrid" : [ "60", "59" ] }
{ "_id" : ObjectId("4f554c9edc1def1a3a3ba62d"), "tagname" : "java",
"mrid" : [ "60" ] }


I need query the list of tagnames along with the size of the array.

the result should be like

select tagname, count(mrid).

result set: sql,2
java,1

How can I get this result?

Nat

unread,
Mar 5, 2012, 8:55:19 PM3/5/12
to mongod...@googlegroups.com

Scott Hernandez

unread,
Mar 5, 2012, 9:04:38 PM3/5/12
to mongod...@googlegroups.com
See group or mapreduce: http://www.mongodb.org/display/DOCS/Aggregation

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>

Ram

unread,
Mar 6, 2012, 8:50:46 PM3/6/12
to mongod...@googlegroups.com
I am looking to get the size of the array. Is it possible with mapreduce. I think this is not possible with group.


On Monday, March 5, 2012 8:04:38 PM UTC-6, Scott Hernandez wrote:

On Mon, Mar 5, 2012 at 8:52 PM, Ram <ramesh...@gmail.com> wrote:
> I have a collection called tags with the documents in the below
> model.
> Each document has a tagname field and mrid field. The mrid field is an
> array.
>
>
> { "_id" : ObjectId("4f554c9ddc1def1a3a3ba62c"), "tagname" : "sql",
> "mrid" : [ "60", "59" ] }
> { "_id" : ObjectId("4f554c9edc1def1a3a3ba62d"), "tagname" : "java",
> "mrid" : [ "60" ] }
>
>
> I need query the list of tagnames along with the size of the array.
>
> the result should be like
>
> select tagname, count(mrid).
>
> result set: sql,2
>               java,1
>
> How can I get this result?
>
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.

> To unsubscribe from this group, send email to mongodb-user+unsubscribe@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages