0

I am new to mongodb, as per requirement I need to get all the keys from below MongoDB document or any other documents, using some dynamic function.

MongoDB example document:

{
      "encryption": {
        "alg":"AES",
        "encryption_key":"lkjhsdflkhsdfwe22348423"
      },
      "domain": "PBTV",
          "detokenObject": [{ 
            "client": {
              "FORENAMES":"^^^ABCDEFG",
              "SURNAME":"^^^ABCDFHE",
              "COUNTRY":"England",          
            "transactions": [ 
              {  
                "TYPE":"buy",
              },
              {  
                "TYPE":"sell",
                "AMT":"1000"
              },{
                "AMT":"1000000000000000001"
              }
            ]
          } ,
            "client1": {
              "SURNAME":"^^^ABCDFHE",
              "COUNTRY":"England",          
            "transactions": [ 
              {  
                "TYPE":"buy",
                "ASSET":"NYSE:APPL",
                "AMT":"100"
              },
              {  
                "TYPE":"sell",
                "ASSET":"NYSE:APPL",
                "AMT":"1000"
              }
            ]     
        }
        }]
    }

Please provide any solution?

Markus W Mahlberg
  • 19,711
  • 6
  • 65
  • 89
Surya Rawat
  • 101
  • 3
  • 13
  • 3
    Please provide me with beer for the rest of my life. What have you tried so far? And, as a side node: there is a [16MB size limit on BSON documents](https://docs.mongodb.org/manual/reference/limits/#BSON-Document-Size). One of my mantras: [Overembedding is the root of all evil.](http://blog.mahlberg.io/blog/2015/11/05/data-modelling-for-mongodb/). – Markus W Mahlberg Feb 15 '16 at 09:59
  • What do you expect in the result? – Alex Blex Feb 15 '16 at 10:00
  • @Markus W Mahlberg :Thanks for your response, so far i have not done much but wrote this function to iterate detokenObject array. db.detoken_vault.aggregate( { $project: { detokenObject: 1 }}, { $unwind: "$detokenObject" }, { $group: { _id: "result", count: { $sum: 1 }}} ); – Surya Rawat Feb 15 '16 at 10:07
  • @AlexBlex : requirement is to write a dynamic function to get all the keys from BSON object and store somewhere in list. – Surya Rawat Feb 15 '16 at 10:11
  • http://stackoverflow.com/questions/2997004/using-map-reduce-for-mapping-the-properties-in-a-collection – Alex Feb 15 '16 at 10:13
  • It would be nice to see what you expect in the result for the given example. "all keys in a list" is quite ambiguous. – Alex Blex Feb 15 '16 at 10:48

0 Answers0