Docs Menu

Docs HomeRealm

Create & Manage User API Keys - Node.js SDK

On this page

  • Create a User API Key
  • Look up a User API Key
  • Enable or Disable an API Key
  • Delete an API Key

To create a new user API key, pass a name that's unique among all of the user's API keys to ApiKeyAuth.create().


You cannot create a user API key for a server API key or an anonymous user.


Store the API Key Value

The SDK only returns the value of the user API key when you create it. Make sure to store the key value securely so that you can use it to log in.

If you lose or do not store the key value there is no way to recover it. You will need to create a new user API key.

To get an array that lists all of a user's API keys, call ApiKeyAuth.fetchAll().

To find a specific API key, pass the key's _id to ApiKeyAuth.fetch().

To enable or disable a user API key, pass the key's _id to ApiKeyAuth.enable() or ApiKeyAuth.disable(). When a key is disabled, it cannot be used to log in on behalf of the user.

To permanently delete a user API, pass the key's _id to ApiKeyAuth.delete(). Deleted keys cannot be recovered.

←  Manage Email/Password Users - Node.js SDKQuery MongoDB - Node.js SDK →
Share Feedback
© 2022 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.