connectVersion: v1.4
Sur cette page
connect()
Ce contenu n’est pas encore disponible dans votre langue.
This function is used to connect simply-xp to a database, and configure client options.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| db | string | ✅ | MongoDB Connection String |
| options | ConnectionOptions | ❌ | The options for the user. |
Returns
Section titled “Returns”- Promise<
void> - Resolves once connected. Other functions called before then wait up to 10 seconds.
Throws
Section titled “Throws”new Error()- If the connection was unsuccessful, or if the URI was not provided.new Error()- If you connect again with a different URI.
[JS] Example
Section titled “[JS] Example”const { connect } = require("simply-xp");
const connectionString = "mongodb+srv://myDatabaseUser:D1fficultP%40ssw0rd@cluster0.example.mongodb.net/?retryWrites=true&w=majority";
connect(connectionString) // Returns Promise<void> .catch((err) => console.log(err)); // Returns the errorConnection Options
Section titled “Connection Options”| Parameter | Type | Required | Description |
|---|---|---|---|
| auto_purge | boolean | ❌ | Delete the records of users who left the guild when leaderboard() runs. [Default: false] |
| notify | boolean | ❌ | Log { XP } Database Connected once connected. [Default: false] |