Question about using unique indexes for Custom Entities
-
Hello BrainCloud Support Team,
I would like to ask about using unique indexes with Custom Entities.
We are currently using Custom Entity with the entityType FOLLOW, and we tried to create an index named test_index with the unique option enabled.
However, the following error occurred:
Error Code: 3010308 Error Message: Error adding custom entity index test_index for entityType FOLLOW Exception: Index cannot be created with 'unique' option as prevents sharding of custom collection. Exception message: Index cannot be created with 'unique' option as prevents sharding of custom collection.We would like to prevent duplicate values for a specific field in this Custom Entity.
Could you please confirm whether Custom Entity indexes support the unique option?
If unique indexes are not supported due to sharding, could you recommend the best alternative approach to enforce uniqueness for a field in Custom Entity?
Thank you.
Best regards,
Gyutae Lee -
Hi @gyutaelee,
Currently, brainCloud blocksuniqueindexes on all custom collections as a blanket safeguard. The check happens unconditionally before the system even evaluates whether your collection is owned or sharded, so it rejects theuniqueoption with that error.We can manually add the unique index for your
FOLLOWcollection on our end. Please send us a request with:- Your
appId - The
entityType(is itFOLLOWonly?) - The field name(s) that need uniqueness
- The desired index name (e.g.,
test_index)
Once we receive your request, we'll add the uniqueness constraint for you directly.
- Your
-
Hello brainCloud team,
We would like to request a unique compound index for our Custom Entity type
FOLLOW.Our App ID is
15389.The
FOLLOWentity stores follow relations with the following data shape:{ "followerId": "profileId_A", "followingId": "profileId_B", "createdAt": 1770000000000 }We want to prevent duplicate follow relations for the same follower/following pair.
Entity Type:
FOLLOWUnique index name:
followerId_followingId_uniqueKeys:
{ "data.followerId": 1, "data.followingId": 1 }Options:
{ "unique": true, "background": true }We already have a non-unique index with the same key pattern:
Index name:
followerId_followingIdKeys:
{ "data.followerId": 1, "data.followingId": 1 }If needed, please replace this existing non-unique index with the unique version.
This feature has not been released to production yet, so we can clean up or reset the
FOLLOWdata before the unique index is applied if necessary.We also have a few questions:
- If this unique index is manually added to the Development app, will it be included automatically when we deploy or migrate to Staging/Production?
- Or does this unique index need to be manually applied per app/environment?
- If it must be applied per environment, can we provide the appIds for Development, Staging, and Production so you can add the same index to each app?
- Are manually added Custom Entity indexes included in brainCloud deploy/migrate/export-import workflows?
- If there are existing duplicate rows for the same
data.followerId + data.followingIdpair, will the unique index creation fail? - Is there any expected downtime, lock, write failure, or performance impact while this index is being created?
- After the index is applied, what is the recommended way to verify that the unique index exists in each environment?
Thank you.