_PushStatus issue after upgrade to 3.1.x
error: Uncaught internal server error. TypeError: Cannot redefine property: _PushStatus
at Function.defineProperty (
Do you happen to have by any chance an _PushStatus object in your _SCHEMA table?
Do you happen to have by any chance an _PushStatus object in your _SCHEMA table?
Yes I do. Parse Server automatically generated this object in version 3.0
Should I delete it instead?
Do you happen to have by any chance an _PushStatus object in your _SCHEMA table?
I tried to delete this object and got another error instead.
warn: Unable to ensure uniqueness for user email addresses: MongoError: Index with name: email_1 already exists with different options
at /app/node_modules/mongodb-core/lib/connection/pool.js:581:63
at authenticateStragglers (/app/node_modules/mongodb-core/lib/connection/pool.js:504:16)
at Connection.messageHandler (/app/node_modules/mongodb-core/lib/connection/pool.js:540:5)
at emitMessageHandler (/app/node_modules/mongodb-core/lib/connection/connection.js:310:10)
at Socket.
What version were you running before upgrading to 3.1? The alert you’re seeing is regarding the _User table.
What version were you running before upgrading to 3.1? The alert you’re seeing is regarding the _User table.
From 3.0.0
Everything works fine in version 3.0.0
I am running parse-server 3.1.0 and also see similar warning when I start up parse-server (npm start).
Warnings on 3 index:
- email_1
- username_1
- name_1
Is there any need to re-create the index on _User table when upgrading to 3.1.0?
warn: Unable to ensure uniqueness for user email addresses: MongoError: Index with name: email_1 already exists with different options
at /Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:581:63
at authenticateStragglers (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:504:16)
at Connection.messageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:540:5)
at emitMessageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:310:10)
at Socket.
Are you able to provide the indexes from mongo perspective? We may have inadvertently mis implemented a feature in 3.1
@flovilmart, I believe these are the 3 indices. First two on _User and the last one on _Role.
{ "v": 1, "key": { "email": 1 }, "name": "email_1", "ns": "xxx._User", "background": true }
{ "v": 1, "key": { "username": 1 }, "name": "username_1", "ns": "xxx._User", "background": true }
{ "v": 1, "unique": true, "key": { "name": 1 }, "name": "name_1", "ns": "xxx._Role" }
According this this thread, you might have added unique constraints in 3.1.0.
https://stackoverflow.com/questions/30232081/mongoexception-index-with-name-code-already-exists-with-different-options/30232270
Would you be able to start a parse-server on a clean DB, and tell me what what do the indexes look like?
I have migrated my DB from parse.com since 2 years ago. I didn't know how to start from a clean DB. Could you point me to some documentation on this? I will try again about 12 hours from now. :-)
Just start a local mongo database. Look into the starting guides on the http://docs.parseplatform.org website
Might have a solution to this. We got the same error: Unable to ensure uniqueness for role name: MongoError: Index with name: name_1 already exists with different options when trying to start with our old DB from parse.com with parse-server 3.1.1.
The issue was that we had an index { "name": 1 } on _Role, but with sparse set to false. So we just deleted the index and parse-server created a new one (the same index, but with sparse set to true on start up.
I created a blank local database and started parse server connecting to the local database. It automatically creates the _User, _SCHEMA, _Role with indexes. This is the mongod log with schema and indexes details.
2018-11-09T06:35:53.161+0800 I COMMAND [conn3327] command parse._SCHEMA command: insert { insert: "_SCHEMA", documents: [ { _id: "_User", objectId: "string", updatedAt: "date", createdAt: "date", username: "string", email: "string", emailVerified: "boolean", authData: "object" } ], ordered: true } ninserted:1 keyUpdates:0 writeConflicts:0 numYields:0 reslen:40 locks:{ Global: { acquireCount: { r: 2, w: 2 } }, Database: { acquireCount: { w: 1, W: 1 } }, Collection: { acquireCount: { W: 1 } } } protocol:op_query 124ms
2018-11-09T06:35:53.166+0800 I COMMAND [conn3329] command parse._Hooks command: find { find: "_Hooks", filter: {}, sort: {}, projection: {}, returnKey: false, showRecordId: false } planSummary: EOF keysExamined:0 docsExamined:0 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:0 nreturned:0 reslen:118 locks:{ Global: { acquireCount: { r: 2 } }, Database: { acquireCount: { r: 1 }, acquireWaitCount: { r: 1 }, timeAcquiringMicros: { r: 109172 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_query 109ms
2018-11-09T06:35:53.209+0800 I COMMAND [conn3328] command parse._SCHEMA command: insert { insert: "_SCHEMA", documents: [ { _id: "_Role", objectId: "string", updatedAt: "date", createdAt: "date", name: "string", users: "relation<_User>", roles: "relation<_Role>" } ], ordered: true } ninserted:1 keyUpdates:0 writeConflicts:0 numYields:0 reslen:40 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1 }, acquireWaitCount: { w: 1 }, timeAcquiringMicros: { w: 121407 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 173ms
2018-11-09T06:35:53.339+0800 I INDEX [conn3329] build index on: parse._User properties: { v: 1, unique: true, key: { username: 1 }, name: "username_1", ns: "parse._User", background: true, sparse: true }
2018-11-09T06:35:53.389+0800 I INDEX [conn3327] build index on: parse._User properties: { v: 1, unique: true, key: { email: 1 }, name: "email_1", ns: "parse._User", background: true, sparse: true }
2018-11-09T06:35:53.389+0800 I INDEX [conn3329] build index done. scanned 0 total records. 0 secs
2018-11-09T06:35:53.389+0800 I INDEX [conn3327] build index done. scanned 0 total records. 0 secs
2018-11-09T06:35:53.401+0800 I COMMAND [conn3328] command parse._SCHEMA command: find { find: "_SCHEMA", filter: {}, returnKey: false, showRecordId: false } planSummary: COLLSCAN keysExamined:0 docsExamined:2 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:0 nreturned:2 reslen:445 locks:{ Global: { acquireCount: { r: 2 } }, Database: { acquireCount: { r: 1 }, acquireWaitCount: { r: 1 }, timeAcquiringMicros: { r: 176282 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_query 188ms
2018-11-09T06:35:53.403+0800 I COMMAND [conn3329] command parse.$cmd command: createIndexes { createIndexes: "_User", indexes: [ { name: "username_1", key: { username: 1 }, unique: true, background: true, sparse: true } ] } keyUpdates:0 writeConflicts:0 numYields:0 reslen:113 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1, W: 2 }, acquireWaitCount: { w: 1, W: 2 }, timeAcquiringMicros: { w: 48296, W: 48466 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 231ms
2018-11-09T06:35:53.406+0800 I COMMAND [conn3327] command parse.$cmd command: createIndexes { createIndexes: "_User", indexes: [ { name: "email_1", key: { email: 1 }, unique: true, background: true, sparse: true } ] } keyUpdates:0 writeConflicts:0 numYields:0 reslen:113 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1, W: 2 }, acquireWaitCount: { W: 2 }, timeAcquiringMicros: { W: 182237 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 235ms
2018-11-09T06:35:53.584+0800 I INDEX [conn3328] build index on: parse._Role properties: { v: 1, unique: true, key: { name: 1 }, name: "name_1", ns: "parse._Role", background: true, sparse: true }
2018-11-09T06:35:53.584+0800 I INDEX [conn3328] build index done. scanned 0 total records. 0 secs
2018-11-09T06:35:53.587+0800 I COMMAND [conn3328] command parse.$cmd command: createIndexes { createIndexes: "_Role", indexes: [ { name: "name_1", key: { name: 1 }, unique: true, background: true, sparse: true } ] } keyUpdates:0 writeConflicts:0 numYields:0 reslen:113 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1, W: 2 }, acquireWaitCount: { W: 1 }, timeAcquiringMicros: { W: 1817 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 179ms
Ok so the main issue is that now we create the indexes as unique + sparse, as you initially envisioned. Now I am not sure of the best resolution:
- ignore the warning
- delete and replace the index
- create the new index under a different name (and then perhaps delete the existing one)
What do you think?
Is "sparse" is used when a field could be left as "undefined". Are these 3 fields optional?
If the "sparse" is required, I suggest to delete and replace the index upon parse-server start up. Does parse-server has sufficient right to drop index? We should not leave unused Index because indices took up precious disk space and cpu time.
Yeah, they do, temporarily, we could create the new one and replace the old one.
Is it something you’d like to implement?
The best way to give back when you receive a favour is to contribute code :-) However, I am not so sure at the moment. Let's me explore a bit further on parse-server codebase.
There is a workaround, and the setup is not completely broken. You could destroy your indexes and restart the server this would ‘just work’. But not as clean as doing a migration.
And as a long time user (as you said), it’s always good to have his hand dirty :)
It works.
I have dropped these indices and then new indices automatically created in next parse-server restart.
_User.email_1
_User.username_1
_Role.name_1
Recreated index on _User { "v": 2, "unique": true, "key": { "email": 1 }, "name": "email_1", "ns": "xxx._User", "background": true, "sparse": true }
{ "v": 2, "unique": true, "key": { "username": 1 }, "name": "username_1", "ns": "xxx._User", "background": true, "sparse": true }
Recreated index on _Role { "v": 2, "unique": true, "key": { "name": 1 }, "name": "name_1", "ns": "xxx._Role", "background": true, "sparse": true }