I want to get the values โโof only certain keys from the MongoDB collection.
But there are several keys in the collection that have a โspaceโ in their name, for example:
"Parent":{"key1": //some string, "key2": //some string, "key 3": //some string}
I know this is the wrong approach, because ideally there should be no spaces in the key name, but nevertheless, how can I request this key? I am using Python and PyMongo.
For regular keys, I can do this:
db.coll_name.find({"key": "India"}, {"_id": 0, "Parent.key1": 1, "Parent.key2": 1})
So, how can I use the key "Parent ['key 3']" in the second argument of the above request? Is there any way to achieve this?
Here's a query that returns data (works):
db.coll_name.find({}, {"Parent.key1": 1, "_id": 0})
Here is a query that does not return data:
db.coll_name.find({}, {"Parent['key 3']": 1, "_id": 0})