-
-
Notifications
You must be signed in to change notification settings - Fork 2
MongoDB
Now, hive-db additionally offers you mongo-db interaction, knowing that you have a mongodb connection uri, which is either localhost
or from MongoDB Atlas
.
For a mongo-db guide refer, here.
Hive-db just eases your mongo code, it reacts with the code interface, or acts as a compiler towards mongodb, it isn't associated with mongo.
const db = require('hive-db');
// Point to be noted, database is a constructor under db.mongo
const {database} = db.mongo;
const mongo= new database("mongodb+srv://wyvern:[email protected]", "JSON", { useUnique: true });
mongo.on("ready", () => {
console.log(`Connected!`);
test();
});
mongo.on("error", console.error);
mongo.on("debug", console.log);
async function test() {
mongo.init('age','21');
mongo.get('age')
//-> 21
mongo.init('name','Lason');
mongo.get('name');
//-> Lason
}
Initialize a value.
mongo.init("foo", "bar");
Get a value.
mongo.get("foo").then(console.log);
//-> bar
Input a value into an existing array.
mongo.input("name");
// assuming that the key name has an array, for example ["Lason", "Tensor"]
Add a value to a data(number) in a key
mongo.add('age', 4)
// adds 4 to the age
Subtract a value from a data(number) in a key
mongo.subtract('age', 4)
// subtracts 4 from the age
Delete the data
mongo.del('age').then(console.log('Deleted'))
// -> Deleted
fetch all elements from an array.
mongo.all('name');
Delete all
mongo.delAll('name');
Create data models!
const age = mongo.table('age')
age.init('name', 'Lason')
age.get('name').then(console.log);
// -> Lason!
The MongoDB adapter mostly provides the methods that the previous adapter (i.e., sqlite adapter) had, although there is a JSON functionality that this adapter provides you.
[
{
"ID":"something",
"data":"something"
}
]
Calling from JSON
db.get("something");
//-> give you something as the output!
This does not require any external effort such as calling the whole file. It understands the format and calls it by its own.
hive-db guide