Quick mongodb wrapper for beginners that provides key-value based interface.
db.watch()
autoConnect
optiondb.useCollection()
alias for db.table
db.pull
shift
/unshift
/pop
/startsWith
/endsWith
/sub
/addSubtract
/getArray
apiconst { QuickDB } = require("quick.db");
// get mongo driver
const { MongoDriver } = require("quickmongo");
const driver = new MongoDriver("mongodb://localhost/quickdb");
driver.connect().then(() => {
console.log(`Connected to the database!`);
init();
});
async function init() {
// use quickdb with mongo driver
// make sure this part runs after connecting to mongodb
const db = new QuickDB({ driver });
// self calling async function just to get async
// Setting an object in the database:
console.log(await db.set("userInfo", { difficulty: "Easy" }));
// -> { difficulty: 'Easy' }
// Getting an object from the database:
console.log(await db.get("userInfo"));
// -> { difficulty: 'Easy' }
// Getting an object property from the database:
console.log(await db.get("userInfo.difficulty"));
// -> 'Easy'
// Pushing an element to an array (that doesn't exist yet) in an object:
console.log(await db.push("userInfo.items", "Sword"));
// -> { difficulty: 'Easy', items: ['Sword'] }
// Adding to a number (that doesn't exist yet) in an object:
console.log(await db.add("userInfo.balance", 500));
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }
// Repeating previous examples:
console.log(await db.push("userInfo.items", "Watch"));
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
console.log(await db.add("userInfo.balance", 500));
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }
// Fetching individual properties
console.log(await db.get("userInfo.balance")); // -> 1000
console.log(await db.get("userInfo.items")); // ['Sword', 'Watch']
// disconnect from the database
await driver.close();
}
Full Changelog: https://github.com/archaeopteryx1/quickmongo/compare/v5.1.2...v5.2.0
Full Changelog: https://github.com/CesiumLabs/quickmongo/compare/v5.1.1...v5.1.2
// permanent
await db.set("test", 123);
// set the data and automatically delete it after 1 minute
await db.set("foo", "bar", 60); // 60 seconds = 1 minute
// fetch the temporary data after a minute
setTimeout(async () => {
await db.get("foo"); // null
await db.get("test"); // 123
}, 60_000);
Full Changelog: https://github.com/CesiumLabs/quickmongo/compare/v5.1.0...v5.1.1
db.table
constructor
db.instantiateChild
. Example:
const table = new db.table("myTable");
table.set("foo", "bar");
Full Changelog: https://github.com/CesiumLabs/quickmongo/compare/v5.0.1...v5.1.0
db.fetch()
db.all()
filter fn now returns object with ID
and data
propsdb.stats()
db.metadata
Full Changelog: https://github.com/CesiumLabs/quickmongo/compare/v5.0.0...v5.0.1
db.all()
(#41)Full Changelog: https://github.com/CesiumLabs/quickmongo/compare/v4.0.0...v5.0.0
QuickMongo v4 is completely rewritten in TypeScript. v4 is completely different from what older versions looked like.
Database
, instead it is a collectionadd
, subtract
, math
, divide
, multiply
, keyArray
, valueArray
, import
etc.has
, get
, set
, delete
, push
, pull
, drop
, all
, latency
and export
.Fields
logic, which is now required.{ ID: string; data: any; }
however, users must use Fields.const { Collection: MongoCollection, MongoClient } = require("mongodb");
const { Collection, Fields } = require("quickmongo");
const mongo = new MongoClient("mongodb://localhost/quickmongo");
const schema = new Fields.ObjectField({
difficulty: new Fields.StringField(),
items: new Fields.ArrayField(new Fields.StringField()),
balance: new Fields.NumberField()
});
mongo.connect()
.then(() => {
console.log("Connected to the database!");
doStuff();
});
function doStuff() {
const mongoCollection = mongo.db().collection("JSON");
const db = new Collection(mongoCollection, schema);
db.set("userInfo", { difficulty: "Easy", items: [], balance: 0 }).then(console.log);
// -> { difficulty: 'Easy', items: [], balance: 0 }
db.push("userInfo", "Sword", "items").then(console.log);
// -> { difficulty: 'Easy', items: ['Sword'], balance: 0 }
db.set("userInfo", 500, "balance").then(console.log);
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }
// Repeating previous examples:
db.push("userInfo", "Watch", "items").then(console.log);
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
const previousBalance = await db.get("userInfo", "balance");
db.set("userInfo", previousBalance + 500, "balance").then(console.log);
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }
// Fetching individual properties
db.get("userInfo", "balance").then(console.log);
// -> 1000
db.get("userInfo", "items").then(console.log);
// -> ['Sword', 'Watch']
// remove item
db.pull("userInfo", "Sword", "items").then(console.log);
// -> { difficulty: 'Easy', items: ['Watch'], balance: 1000 }
}
QuickMongo v2.0.6 is released 🎉
-
db#table()
has been deprecated
and will be removed in next update. Please switch to db#createModel()
instead
-
Fixed a bug : db#get
used to return null
for false
values | db#has
used to return false
for false
values which includes false
, 0
etc.
-
Other minor changes
Docs: https://quickmongo.js.org GitHub: https://github.com/DevSnowflake/quickmongo NPM: https://npmjs.com/package/quickmongo