Can mongodb generate a dictionary of dictionaries?

295 views
Skip to first unread message

Robert

unread,
Jan 9, 2015, 2:27:37 PM1/9/15
to mongod...@googlegroups.com
(I appreciate that a collection is essentially a list of dictionaries.  I often have need of a dictionary or dictionaries instead.)


Is there a way to run a procedure on the collection that, for each dictionary (json) in the collection list

a) allows me establish a function that will compute a key
b) checks whether the key exists (in a new dictionary collection, not a list collection)
c) if the key exists, allows me to update the amount fields in the existing item (add amounts
d) if the key doesn't exist, allows me to create a new json with non-amount fields and zero value amount fields and then update similar to c

By choosing the key carefully, sorting and also summarization of the data will be taken care of.  That is to say, often I need some details show but other details collapsed.

All of this is very helpful for report and financial data.




Additionally, it is nice if

a) there would be a function that would take the new dictionary of dictionaries established above and also a list and create a grid (spreadsheet) that is row-ordered by the keys in the dictionary and is column-ordered by the fields in the list.


Thanks



Asya Kamsky

unread,
Jan 10, 2015, 12:14:45 AM1/10/15
to mongodb-user
Robert:

I'm not sure I'm understanding you correctly because it sounds to me
like you want to take a MongoDB collection of documents and represent
it as a single document (which has many embedded documents as values).
Am I mapping what you are trying to do correctly?

Is this to do some sort of aggregation? Can you give a mocked up
example of starting list (collection) and result document (dictionary)
so I can see if I'm on the right track coming up with an answer?

Asya
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user"
> group.
>
> For other MongoDB technical support options, see:
> http://www.mongodb.org/about/support/.
> ---
> 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...@googlegroups.com.
> To post to this group, send email to mongod...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mongodb-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mongodb-user/7f8a6a6d-9076-496a-bc05-7db6709d6b3d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages