Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pymongo 4.x not support ensure_index #122

Open
dingwf opened this issue Jun 23, 2022 · 1 comment
Open

pymongo 4.x not support ensure_index #122

dingwf opened this issue Jun 23, 2022 · 1 comment

Comments

@dingwf
Copy link

dingwf commented Jun 23, 2022

PyMongo 4.x aready remove ensure_index(), should use create_index() or create_indexes().

https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html#id43

@alex-shef
Copy link

The same problem, doesn't work with MongoDB.
TypeError: 'Collection' object is not callable. If you meant to call the 'ensure_index' method on a 'Collection' object it is failing because no such method exists.

Is it correct code?

app = Flask(__name__)

client = MongoClient("mongodb://mongodb:27017/")
db = client["mydatabase"]
collection = db["mycollection"]

# Creating a uniqueness index for the "key" field
collection.create_index([("key", 1)], unique=True)

# flask-profiler config
app.config["flask_profiler"] = {
    "enabled": app.config["DEBUG"],
    "storage": {
        "engine": "mongodb",
        "MONGO_URL": "mongodb://mongodb:27017/",
        "DATABASE": "mydatabase",
        "COLLECTION": "mycollection",
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants