mongo-axium
v1.0.4
Published
Axium Mongo Database.
Downloads
82
Maintainers
Readme
Installation
npm i mongo-axium
Example With MongoDriver
const { QuickDB } = require("mongo-axium");
const { MongoDriver } = require("mongo-axium/MongoDriver");
(async () => {
const mongoDriver = new MongoDriver("mongodb://localhost/axium-mongo");
await mongoDriver.connect();
const db = new QuickDB({ driver: mongoDriver });
await db.set("userInfo", { difficulty: "Easy" });
// -> { difficulty: 'Easy' }
await mongoDriver.close();
// disconnect from the database
})();
Example Database Usage
(async () => {
// self calling async function just to get async
// Setting an object in the database:
await db.set("userInfo", { difficulty: "Easy" });
// -> { difficulty: 'Easy' }
// Getting an object from the database:
await db.get("userInfo");
// -> { difficulty: 'Easy' }
// Getting an object property from the database:
await db.get("userInfo.difficulty");
// -> 'Easy'
// Setting an object in the database:
await db.set("userInfo", { difficulty: "Easy" });
// -> { difficulty: 'Easy' }
// Pushing an element to an array (that doesn't exist yet) in an object:
await db.push("userInfo.items", "Sword");
// -> { difficulty: 'Easy', items: ['Sword'] }
// Adding to a number (that doesn't exist yet) in an object:
await db.add("userInfo.balance", 500);
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }
// Repeating previous examples:
await db.push("userInfo.items", "Watch");
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
await db.add("userInfo.balance", 500);
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }
// Fetching individual properties
await db.get("userInfo.balance"); // -> 1000
await db.get("userInfo.items"); // ['Sword', 'Watch']
})();