How do I learn the fields/keys of a collection?

19 views
Skip to first unread message

Sky USC

unread,
Mar 9, 2012, 5:00:59 PM3/9/12
to mongod...@googlegroups.com
I am new. please help.
 
I roughly have a collection with approx 5 million rows. The schema looks like this:
 
* ID : Folder.1108
* location : memphis
* DocType :
   * "jpg" : 53    
   * "gif"  : 41
 
* ID : Folder.1109
* location : memphis
* DocType :
* "pdf" : 15    
* "jpg" : 3
 
* ID : Folder.1110
* location : portland
* DocType :
   * "pdf" : 39    
   * "gif" : 21
   * "jar" : 6
     etc etc.. and there could be unknown types of document extensions.
 
I am trying to find the command to
1. List - what are the distinct names of file extensions possibly found in all of the documents. Can this be done without iterating thru each of the documents? Also, hopefully with ability to find extensions that are only in the "memphis" location.
2. Possibly find the actual count of "jpg" in memphis location alone.
 
Thx.
 

Scott Hernandez

unread,
Mar 9, 2012, 5:38:20 PM3/9/12
to mongod...@googlegroups.com

I'm afraid you need to go through them all. You can limit the ones you
need to go through with a query including the location.

> 2. Possibly find the actual count of "jpg" in memphis location alone.

You could change your structure to this:

{ ID : "Folder.1109", location : "memphis", DocType : [ {type:"pdf" :
count:15}, {type:"jpg" : count:3}]}
to be able to find({location:"memphis", "DocType.type":"pdf"})

using this index: {location:1, "DocType.type": 1}

> Thx.
>
>
> --
> 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.

Sky USC

unread,
Mar 9, 2012, 7:21:16 PM3/9/12
to mongod...@googlegroups.com
Thx. The "Type"/"Count" suggestion works well!

Scott Hernandez

unread,
Mar 9, 2012, 7:23:50 PM3/9/12
to mongod...@googlegroups.com
If you are storing lots of those you may want to just use t/c instead
of the whole words.
Reply all
Reply to author
Forward
0 new messages