In this tutorial, we will explore how to create a new user in the Milvus server using the Node.js Milvus SDK.
Dependencies:
- Milvus server
- Node: v12+
Install the Milvus Node.js SDK
The first step is downloading and installing the Milvus SDK for Node.js. You can do this using NPM or YARN as shown in the following command:
yarn add @zilliz/milvus2-sdk-node
This donwloads the Milvus Node.js client and adds a dependency entry in your “package.json” file.
Connect to Milvus
Once you have the package installed in your project, create a new “JavaScript” file to store the source code for your project.
Next, add the code as shown in the following to connect to the Milvus server:
const address = 'your-milvus-ip-with-port';
const username = 'your-milvus-username'; // optional username
const password = 'your-milvus-password'; // optional password
// connect to milvus
const client = new MilvusClient({ address, username, password });
If you have not enabled the authentication for your Milvus cluster, you can skip the username and password combination as they are not required by default.
Create a User
However, if you enabled the authentication for your server, you can use the CreateUser() method to configure a new Milvus user.
An example method usage is as follows:
new milvusClient(MILUVS_ADDRESS).createUser({
username: "milvus",
password: "milvus",
});
The username and password parameters are used to specify the user and password combination that you wish to create. Upon success, the method should return a JSON response as follows:
Delete the User
Once you are done, you can remove the user using the DeleteUser() method. An example usage is as follows:
new milvusClient(MILUVS_ADDRESS).deleteUser({
username: "milvus",
});
This should drop the user with the specified username and return the corresponding JSON response. If the removal is successful, the method should return an output as follows:
Conclusion
In this tutorial, we explored how to create a new Milvus user using the CreateUser() method provided by the Node.js SDK. You can explore the official documentation to gather more information.