Closed Nelly-Barret closed 3 weeks ago
I CAN insert from mongosh
But I CAN'T from pymongo!
(I did it from the Python cmd-line)
>>> from pymongo import MongoClient
>>> client = MongoClient()
>>> print(client)
MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True)
>>> db = client["mytest"]
>>> print(db)
Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'mytest')
>>> db["mytable"].insert_one({"a": 23})
Traceback (most recent call last):
.....
AttributeError: '_Transaction' object has no attribute 'drop'
But I can do a find apparently. So this seems to be something related to the insert itself, not the database or the connection:
❯ python3
Python 3.12.3 (v3.12.3:f6650f9ad7, Apr 9 2024, 08:18:48) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pymongo import MongoClient
>>> client = MongoClient()
>>> print(client)
MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True)
>>> db = client["mytestdd"]
>>> print(db)
Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'mytestdd')
>>> db["mytable"].find()
<pymongo.cursor.Cursor object at 0x106c84ec0>
>>> db["mytable"].find({})
<pymongo.cursor.Cursor object at 0x106c85040>
>>> db["mytable"].find({"de": "z3"})
<pymongo.cursor.Cursor object at 0x106c85070>
But I cannot iterate over it:
>>> for my_element in db["mytable"].find({"de": "z3"}):
... print(my_element)
Traceback (most recent call last):
.....
AttributeError: '_Transaction' object has no attribute 'drop'
I have fixed the problem 🥳
What I did:
brew uninstall mongodb-community \nbrew uninstall mongodb-database-tools\nbrew uninstall mongosh\nbrew untap mongodb/brew
rm -f /usr/local/Cellar/mongosh
rm -f /usr/local/Cellar/mongodb-atlas-cli
rm /usr/local/etc/mongod.conf
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
rm -f ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
launchctl remove homebrew.mxcl.mongodb-community
rm /usr/local/bin/mongosh
rm -rf /usr/local/var/log/mongodb
rm -rf /usr/local/var/mongodbold
rm -rf /usr/local/var/mongonelly
sudo lsof -iTCP -sTCP:LISTEN | grep mongo
shows PIDs of running Mongo processes --> kill them
brew tap mongodb/brew
brew install mongodb-community@7.0
For instance in my documents (not under /usr or such, where we can have permission issues)
mongod -dbpath /Users/nelly/Documents/mongodb-data
The above fix is not really a fix because I can isnert data with a Python3 cmd line, but not with my venv activated. I will recreate my venv and reinstall the dependencies to see if this solved the problem
Yes, this solves the problem. Why? Because yesterday I renamed my method reset()
into drop()
and this has also renamed in the libraries Python files...... 👹
I marked the .venv folder as excluded in PyCharm to avoid this happens again
Since this afternoon I have this error:
Even when I go on the
main
branch, I cannot insert in any database. However, I can insert data from the Mongosh cmd-line within Compass.In particular I do not see them in the list (
show databases
) which might be a symptom.The error message may not be totally related to the error and/or not show the exact reason of the cause.