0

whenever i do in my mongodb

db.knowledge.find({},{'_id':0,'information':0})

i'm getting result as

{{'keywords': ['link', 'faculty', 'of', 'agriculture', 'admission', 'undergraduate', 'requirements', 'entry', 'full', 'time', 'foa']}

i wanted to know how to get it in flask. i'm trying it as

dbkeywords = knowledge.find({},{'_id':0,'information':0})
print(dbkeywords[0])

i'm getting

{'keywords': ['link', 'faculty', 'of', 'agriculture', 'admission', 'undergraduate', 'requirements', 'entry', 'full', 'time', 'foa']}

i just want it to be like this:

['link', 'faculty', 'of', 'agriculture', 'admission', 'undergraduate', 'requirements', 'entry', 'full', 'time', 'foa']

just like an array/list

4
  • You have to unwind the field keywords. Commented Mar 27, 2018 at 13:22
  • sorry sir, i'm completely new to flask and mongodb, what does 'unwind the field keywords' means ? help me :/ Commented Mar 27, 2018 at 13:27
  • In essence: an unwind splits an embedded list into multiple docs. You can take a look at the docs: api.mongodb.com/python/current/examples/aggregation.html Commented Mar 27, 2018 at 14:16
  • Thank you to you, i knew another thing 'unwind' :D Commented Mar 27, 2018 at 14:53

1 Answer 1

1

You can convert the returned data into a dictionary. Then, to access the list itself in {'keywords': ['link', 'faculty', 'of', 'agriculture', 'admission', 'undergraduate', 'requirements', 'entry', 'full', 'time', 'foa']}, you just do:

temp = {'keywords': ['link', 'faculty', 'of', 'agriculture', 'admission', 'undergraduate', 'requirements', 'entry', 'full', 'time', 'foa']}
the_list = temp['keywords']
print(the_list)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, genius :D
Hello sir , i'm trying to get max value of a field but unable to get any answer maxPercentage = findmax.find().sort({'percentagematch':-1.0}).limit(1) print(maxPercentage)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.