Repository navigation
Closed
Description
Issue Description
Parse-Server responds with a HTTP 500 when trying to save a duplicate value on an indexed unique column.
Steps to reproduce
1.- Setup a new parse-server instance and add a field of the type String to the table.
2.- Create a unique index on that field
3.- Try to save 2 records with the same value for the indexed field.
Expected Results
The server should return a Parse.Error.DUPLICATE_VALUE, error code
Actual Outcome
The server responds with a HTTP 500:
error: Error generating response. { MongoError: E11000 duplicate key error index:
error: Uncaught internal server error. { MongoError: E11000 duplicate key error index:
Environment Setup
-
Server
- parse-server version 2.7.2
- Operating System: Windows & Linux
- Hardware: DigitalOcean droplet, my computer,
- Localhost or remote server? both
-
Database
- MongoDB version: 3.4.11
- Storage engine: wiredTiger
- Hardware: 1 GB Memory / 25 GB Disk / SFO2
- Localhost or remote server? DigitalOcean, localhost
Logs/Trace
error: Error generating response. { MongoError: E11000 duplicate key error index: ecommerce-universal.ProductCat.$name_1 dup key: { : "YAMATO" }
at C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\pool.js:595:61
at authenticateStragglers (C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\pool.js:513:16)
at Connection.messageHandler (C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\pool.js:549:5)
at emitMessageHandler (C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\connection.js:309:10)
at Socket.<anonymous> (C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\connection.js:452:17)
at Socket.emit (events.js:159:13)
at addChunk (_stream_readable.js:265:12)
at readableAddChunk (_stream_readable.js:252:11)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onread (net.js:598:20)
name: 'MongoError',
message: 'E11000 duplicate key error index: ecommerce-universal.ProductCat.$name_1 dup key: { : "YAMATO" }',
ok: 0,
errmsg: 'E11000 duplicate key error index: ecommerce-universal.ProductCat.$name_1 dup key: { : "YAMATO" }',
code: 11000,
codeName: 'DuplicateKey' } name=MongoError, message=E11000 duplicate key error index: ecommerce-universal.ProductCat.$name_1 dup key: { : "YAMATO" }, ok=0, errmsg=E11000 duplicate key error index: ecommerce-universal.ProductCat.$name_1 dup key: { : "YAMATO" }, code=11000, codeName=DuplicateKey
error: Uncaught internal server error. { MongoError: E11000 duplicate key error index: ecommerce-universal.ProductCat.$name_1 dup key: { : "YAMATO" }
at C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\pool.js:595:61
at authenticateStragglers (C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\pool.js:513:16)
at Connection.messageHandler (C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\pool.js:549:5)
at emitMessageHandler (C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\connection.js:309:10)
at Socket.<anonymous> (C:\Users\elios\elios' files\Projects\X-Evolvers\PRGNRS\ecommerce-universal\node_modules\mongodb-core\lib\connection\connection.js:452:17)
at Socket.emit (events.js:159:13)
at addChunk (_stream_readable.js:265:12)
at readableAddChunk (_stream_readable.js:252:11)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onread (net.js:598:20)
name: 'MongoError',
message: 'E11000 duplicate key error index: ecommerce-universal.ProductCat.$name_1 dup key: { : "YAMATO" }',
ok: 0,
This was working as expected before, I tried going back to older parse-server versions but even so, keeps happening.
Metadata
Metadata
Assignees
Labels
No labels
Activity
dplewis commentedon Feb 8, 2018
Parse Server allows you to create indexes but not unique indexes.
Can you post some sample code?
Did you go though a Mongo Service like MLab or use Mongo Shell?
test for parse-community#4542
elios264 commentedon Feb 8, 2018
Hi @dplewis,
I tried both, custom mongo installation, and Mlab, you are right, Parse don't allow you to create unique indexes, but I created them directly through Mlab or using the
mongodbpackage,About the code sample:
I know creating unique indexes can not be done through the Parse Server api,
but Parse does create unique indexes internally for username and email on the
_Userclass, and when you try to save a duplicate Parse responds with aParse.Error.DUPLICATE_VALUE,I know since this is not currently supported by Parse Server, this could not be considered as an issue,
and I could create a beforeSave trigger and look for the value before proceeding, but I feel that the db indexes are the best and most efficient place to put this logic.
Thank you for attending this issue!
dplewis commentedon Feb 8, 2018
@elios264 Thanks for the quick response. I don't see why we couldn't add unique indexes as a feature of Parse in the future. But for now I can put together a pull request for this.