payload: unique option is not working for text field ?
Bug Report
i just installed a fresh copy of payload cms just added a new field ‘userName’ like below to Users.js
{ name: "userName", type: "text", index: true, required: true, unique: true, },
the new user creation should not go through, if we have same userName , but the unique checks are not happening ?
i am able to add new users with same user name ?
however the required option is working.
also no index is created even while i used index key above ?
new record with same userName should not go through, also an index should be created with unique flag .
i am using Win 10 , Mongodb 5.0.1 , node 16.13.1
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (13 by maintainers)
A related bug #859 was fixed in release v1.0.12 that had to do with unique indexes. All the problems with indexing should be resolved now. @andwrobs, this covers the bug you pointed out in the demo.
We also decided to not do anything in the short term regarding the idea to add a payload script for building indexes. The reason for this decision is that:
diffIndexes()andensureIndexes()which can be called on the Model. See https://mongoosejs.com/docs/api.html#model_Model-diffIndexes and https://mongoosejs.com/docs/api.html#model_Model-ensureIndexesI’m going to close this issue for now because I think we have addressed everything in the thread. Please open any new issues or discussions for new features as needed. Thanks everyone who contributed!
Hi Dan,
Great suggestion of --dry-run , i think in dev ENV/debug mode it should list the indexes that are miss match or need to be created and a message/command, suggesting a flag to be added for auto index creation , it must also look up total records count for the respective index like up till 1000 and also suggest the performance issue while enabling the index flag.
i am still new to Node/JS so its up for suggestion and discussion .
Lastly i must say, i am testing Payload for just 1 day , i am fairly impressed with the possibility it offers, great work!
we tried and it works with adding option
localized: falsein the text field. we use mongodb atlas as a source of database