#community-help

Handling Multi-Tenancy with API Keys in Collections

TLDR CaptainCodeman inquired about using API keys for multi-tenancy in collections. Jason suggested generating unique document IDs by prefixing them with the tenantId.

Powered by Struct AI
5
25mo
Solved
Join the chat
Aug 29, 2021 (25 months ago)
CaptainCodeman
Photo of md5-d3a4ca49ba4aeb3b9d0cb7d846eb0989
CaptainCodeman
07:44 PM
Q: about the API keys feature and using it for multi-tenancy … I take it each tenant still needs to have their own separate collection, otherwise document IDs could conflict?
Aug 30, 2021 (25 months ago)
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:35 AM
CaptainCodeman Not necessarily, you can put all tenants documents in a single collection... Unless document IDs between tenants collide on your end?
CaptainCodeman
Photo of md5-d3a4ca49ba4aeb3b9d0cb7d846eb0989
CaptainCodeman
01:14 AM
there's no guarantee they won't, so I'll create separate collections. I wondered if it worked like AppEngine Datastore where each namespace could have their own unique data, even for the same IDs
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:15 AM
You could generate document IDs using a prefix on your side. So something like tenantId-documentId
CaptainCodeman
Photo of md5-d3a4ca49ba4aeb3b9d0cb7d846eb0989
CaptainCodeman
02:41 AM
that would work too, and I guess give the option of querying one or all