getting a really roadblocking error in pymongo
here, which prevents me from proceeding in a project. I have searched this case but other similar posts and their answers did not work for me.
First of all, I'm running:
mongod v3.6.5-2-g9b2264cf14
MongoDB shell version v3.6.5-2-g9b2264cf14
This is my minimal working / error producing example:
myname@myhost ~ $ /usr/bin/python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> db = pymongo.MongoClient("localhost:27017")
>>> db.testcollection.insert({"foo": "bar"})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pymongo/collection.py", line 2344, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the 'insert' method on a 'Database' object it is failing because no such method exists.
>>>
Other StackOverflow topic have suggested using insert_one()
instead. However, this yields the same result for me:
myname@myhost ~ $ /usr/bin/python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> db = pymongo.MongoClient("localhost:27017")
>>> db.testcollection.insert_one({"foo": "bar"})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pymongo/collection.py", line 2344, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Database' object it is failing because no such method exists.
Any help is appreciated!
Try:
import pymongo
client = pymongo.MongoClient()
db = client[ "testdb" ] # makes a test database called "testdb"
col = db[ "testcol" ] #makes a collection called "testcol" in the "testdb"
col.insert_one( {"foo" : "bar" }) #add a document to testdb.testcol
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With