pymongo.cursor.Cursor object at 0x

923 views
Skip to first unread message

Oleg Petrov

unread,
Jul 27, 2015, 4:38:27 PM7/27/15
to mongodb-user
Hello! Please help me
I want to display in Flask all my data from mongodb by pymongo driver.
After run i see in browser

<pymongo.cursor.Cursor object at 0x7fe1aacc1ed0>

What is it?


my web.py:



from flask  import Flask, render_template
from flask.ext.pymongo import PyMongo

app = Flask(__name__)
mongo = PyMongo(app)


@app.route("/")
def home_page():
    name = mongo.db.megoloman_db.myCollections.find()
    return render_template('cities.html', name = name)

if __name__ == "__main__":
    app.run(debug=True) 



my html:



<!doctype html>
<title>Hello from Flask</title>

  <h1>{{ name }}</h1>

Bernie Hackett

unread,
Jul 28, 2015, 2:10:43 PM7/28/15
to mongodb-user, kirill.b...@gmail.com, kirill.b...@gmail.com
The find() method returns a Cursor instance. You have to iterate that cursor to retrieve the results. You can also do this to get the results as a list:

documents = list(name = mongo.db.megoloman_db.myCollections.find())

Note however, that depending on the size if the collection that can take a lot of memory.

Bernie Hackett

unread,
Jul 28, 2015, 2:27:33 PM7/28/15
to mongod...@googlegroups.com
Sorry, that should have read:

documents = list(mongo.db.megoloman_db.myCollections.find())

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/BSnrOR6n0c4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/71191e89-056f-47b7-a55d-de665fd0210e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oleg Petrov

unread,
Jul 28, 2015, 4:58:25 PM7/28/15
to mongodb-user, kirill.b...@gmail.com
error has gone, but content doesn't display, it returns just empty list [] in browser.

понеділок, 27 липня 2015 р. 23:38:27 UTC+3 користувач Oleg Petrov написав:

Bernie Hackett

unread,
Jul 28, 2015, 5:18:01 PM7/28/15
to mongod...@googlegroups.com
Do you have any documents in the collection you are querying?

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/BSnrOR6n0c4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.

Oleg Petrov

unread,
Jul 29, 2015, 6:29:53 AM7/29/15
to mongodb-user, ber...@mongodb.com

No, only json data. It strangely, because from mongo shell i get what i querying.
середа, 29 липня 2015 р. 00:18:01 UTC+3 користувач Bernie Hackett написав:

Oleg Petrov

unread,
Jul 29, 2015, 7:36:35 AM7/29/15
to mongodb-user, kirill.b...@gmail.com
I found that i should fix the data in the MongoDB console by iterating through the collection and the array and converting each element to an ObjectId.
How can I do this?

понеділок, 27 липня 2015 р. 23:38:27 UTC+3 користувач Oleg Petrov написав:
Hello! Please help me
Reply all
Reply to author
Forward
0 new messages