Django and Mongodb

I have an install of mongo and django setup with virtualenv.

Everything works great until I try to use pymongo to connect to the mongo server.

I get the connection, and I can see the database, but when I run the following test I get unicode errors.

>>> import django
>>> import pymongo
>>> connection = pymongo.Connection("localhost", 27017)
>>> db = connection.test
>>> db.name()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: 'unicode' object is not callable</module></console>

I'm not sure what that means or how to fix it. Does anyone have suggestions?

2 Replies

Drop the parens. What the traceback is telling you is that you're trying to call a Unicode string like a function, i.e.:

In [1]: spackle = "wasps"

In [2]: spackle()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/jsmith/ <ipython console="">in <module>()

TypeError: 'str' object is not callable</module></ipython>

Try typing just:

>>> db.name

The documentation for database.name explains that it was changed to a property instead of a method (maybe recently).

Thanks.. that was the problem. So my install is work as needed. Sweet.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct