0

I know this might be easy, just help me with the reduce function to count using the length of documents.

I have large dataset and I want to count the number of records whose number of key value pairs is 44 and those who are below it.

example. set of my collection

Obj1 - {44 fields} Type Object
Obj2 - {44 fields} Type Object
Obj3 - {44 fields} Type Object
Obj4 - {44 fields} Type Object
Obj5 - {2 fields} Type Object
Obj6 - {1 fields} Type Object
Obj7 - {44 fields} Type Object

I want to get the count 5 for 44 and 2 of < 44.

Meku
  • 107
  • 4
  • Possible duplicate of [How to query for documents where array size is greater than one (1) in mongodb](http://stackoverflow.com/questions/7811163/how-to-query-for-documents-where-array-size-is-greater-than-one-1-in-mongodb) – Shrabanee Jun 07 '16 at 04:51

1 Answers1

0

Try this:

> var equals_to_44 = 0;
> var non_equal_to_44 = 0;
> db.your_collection.find().forEach(function(x) { count=0; for(field in x) { count++; } if (count==44){equals_to_44++;} else {non_equal_to_44++;} })
Celia
  • 345
  • 1
  • 8