Search code examples
pythonmongodbpymongodata-miningtext-mining

How to list the outer-most fields of a large document usign PyMongo?


I am just having difficulties to understand this, how can I list outer-most fields when I am working with a huge text datasets? I am trying to implement it in Mongodb and pymongo? any suggestions?


Solution

  • I am not sure what you need, but maybe the bellow can help.

    Query

    • this query returns an array with all the names of the outer fields
    • objectToArray to convert ROOT document to array
    • get the first member that is the field name

    PlayMongo

    aggregate(
    [{"$project": 
        {"_id": 0,
          "outer-fields": 
          {"$map": 
            {"input": 
              {"$map": 
                {"input": {"$objectToArray": "$$ROOT"},
                  "in": ["$$m.k", "$$m.v"],
                  "as": "m"}},
              "in": {"$arrayElemAt": ["$$this", 0]}}}}}])