diff --git a/docs/changelog.rst b/docs/changelog.rst index 08e5a490..d5ee2b23 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,6 +14,7 @@ dev - Use new update_one, update_many on document/queryset update #1491 - Use insert_one, insert_many in Document.insert #1491 - Fix reload(fields) affect changed fields #1371 +- Fix Read-only access to database fails when trying to create indexes #1338 Changes in 0.15.0 ================= diff --git a/mongoengine/document.py b/mongoengine/document.py index 109f8f82..0d471c3a 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -195,7 +195,10 @@ class Document(BaseDocument): # Ensure indexes on the collection unless auto_create_index was # set to False. - if cls._meta.get('auto_create_index', True): + # Also there is no need to ensure indexes on slave. + db = cls._get_db() + if cls._meta.get('auto_create_index', True) and\ + db.client.is_primary: cls.ensure_indexes() return cls._collection