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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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?