nishant kumar nishant kumar - 1 month ago 17
Python Question

Get all the values of a particular key

I have a data in mongoDB, I want to retrieve all the values of a key

"category"
using python code. I have tried several ways but in every case I have to give the "value" to retrieve. Any suggestions would be appreciated.

{
id = "my_id1"
tags: [tag1, tag2, tag3],
category: "movie",
},
{
id = "my_id2"
tags: [tag3, tag6, tag9],
category: "tv",
},
{
id = "my_id3"
tags: [tag2, tag6, tag8],
category: "movie",
}


I want the output as

category: "movie"
category: "tv"
category: "movie"

Answer
This Should Work

db.test.find({},{"category":1});
Comments