Storing Usernames

Below you can find examples in js and ts of how to storing usernames and names, and checking if a username exists

JavaScript

(async() => {
const AbcDB = require("abc.db");
const DB = new AbcDB("mongo string", "data");
const UserDB = DB.Collection("users");
const data = {
    username: "user_name",
    name: "User Name"
}
if (UserDB.has(data.username) return console.log("User already exists");
await UserDB.set(data.username, data);
})();

TypeScript

import AbcDB from "abc.db";
(async() => {
const DB = new AbcDB("mongo string");
const UserDB = DB.Collection("users", "data");
const data: <{username: string, name: string}> = {
    username: "user_name",
    name: "User Name"
}
if (UserDB.has(data.username)) return console.log("User already exists");
await UserDB.set(data.username, data);
})();

Last updated