azure-database icon indicating copy to clipboard operation
azure-database copied to clipboard

Can't use cosmoDB readonly key / Must use cosmoDB readwrite key

Open vinaybedre opened this issue 1 year ago • 4 comments

I'm submitting a...


[ ] Regression 
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

The library usage requires us to have read-write cosmodb API key, where as it could be used for a readonly purpose with a readonly key. In this line, https://github.com/nestjs/azure-database/blob/78511e49b8af060bccbadd55a5eae0f58a84542d/lib/cosmos-db/cosmos-db-core.module.ts#L26 we try to run a createIfNotExists which needs a readwrite key.

Expected behavior

The library must be able to use with both readonly and readwrite keys. We could enhance the module options with a isReadOnly property, which skips running createIfNotExists

Minimal reproduction of the problem with instructions

  1. Create any cosmodb in azure portal.
  2. Get the primary/secondary readonly keys to use in the library.
  3. Use the module AzureCosmosDbModule in a nestjs app with readonly key

What is the motivation / use case for changing the behavior?

Flexibility. There could be business usecases, where some of the micro services should only have readonly access to the database, instead of readwrite. Currently this flexibility is missing in the library.

Environment


Nest version: 10.3.7

 
For Tooling issues:
- Node version: v20.11.1  
- Platform: Mac 

Others:

vinaybedre avatar Aug 16 '24 05:08 vinaybedre