What is the Python version of Object.keys()?

Viewed 18940

Suppose I specify a MongoDB cursor with pymongo, which DOES NOT include all fields in the result set like this:

from pymongo import MongoClient
conn = MongoClient('mongodb://localhost:27017')
cur = conn['my_db']['my_collection'].find({},{'_id' : 0, 'my_unwanted_field' : 0})

Is there a function or attribute that will return me the names of the fields present in cur.

Something equivalent on Mongo Shell using findOne would be:

> var cur = findOne({},{'_id' : 0, 'my_unwanted_field' : 0})
> Object.keys(cur)

["field_1", ... , "field_n"]
1 Answers
Related