@@ -7,7 +7,6 @@ Quick Mongodb wrapper for beginners that provides key-value based interface.
7
7
# Installing
8
8
9
9
``` bash
10
- $ npm install --save mongodb # required
11
10
$ npm install --save quickmongo
12
11
```
13
12
@@ -16,7 +15,6 @@ $ npm install --save quickmongo
16
15
17
16
# Features
18
17
- Beginner friendly
19
- - Strongly typed
20
18
- Asynchronous
21
19
- Dot notation support
22
20
- Key-Value like interface
@@ -25,55 +23,47 @@ $ npm install --save quickmongo
25
23
# Example
26
24
27
25
``` js
28
- const { Collection: MongoCollection , MongoClient } = require (" mongodb" );
29
- const { Collection , Fields } = require (" quickmongo" );
30
-
31
- const mongo = new MongoClient (" mongodb://localhost/quickmongo" );
32
- const schema = new Fields.ObjectField ({
33
- difficulty: new Fields.StringField (),
34
- items: new Fields.ArrayField (new Fields.StringField ()),
35
- balance: new Fields.NumberField ()
26
+ const { Database } = require (" quickmongo" );
27
+
28
+ const db = new Database (" mongodb://localhost/quickmongo" );
29
+
30
+ db .on (" ready" , () => {
31
+ console .log (" Connected to the database" );
32
+ doStuff ();
36
33
});
37
34
38
- mongo .connect ()
39
- .then (() => {
40
- console .log (" Connected to the database!" );
41
- doStuff ();
42
- });
35
+ db .connect ();
43
36
44
37
function doStuff () {
45
- const mongoCollection = mongo .db ().collection (" JSON" );
46
-
47
- const db = new Collection (mongoCollection, schema);
48
-
49
- db .set (" userInfo" , { difficulty: " Easy" , items: [], balance: 0 }).then (console .log );
50
- // -> { difficulty: 'Easy', items: [], balance: 0 }
38
+ // Setting an object in the database:
39
+ await db .set (" userInfo" , { difficulty: " Easy" });
40
+ // -> { difficulty: 'Easy' }
51
41
52
- db .push (" userInfo" , " Sword" , " items" ).then (console .log );
53
- // -> { difficulty: 'Easy', items: ['Sword'], balance: 0 }
42
+ // Pushing an element to an array (that doesn't exist yet) in an object:
43
+ await db .push (" userInfo.items" , " Sword" );
44
+ // -> { difficulty: 'Easy', items: ['Sword'] }
54
45
55
- db .set (" userInfo" , 500 , " balance" ).then (console .log );
46
+ // Adding to a number (that doesn't exist yet) in an object:
47
+ await db .add (" userInfo.balance" , 500 );
56
48
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }
57
49
58
50
// Repeating previous examples:
59
- db .push (" userInfo" , " Watch" , " items " ). then ( console . log );
51
+ await db .push (" userInfo.items " , " Watch" );
60
52
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
61
-
62
- const previousBalance = await db .get (" userInfo" , " balance" );
63
- db .set (" userInfo" , previousBalance + 500 , " balance" ).then (console .log );
53
+ await db .add (" userInfo.balance" , 500 );
64
54
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }
65
55
66
56
// Fetching individual properties
67
- db .get (" userInfo" , " balance" ).then (console .log );
68
- // -> 1000
69
- db .get (" userInfo" , " items" ).then (console .log );
70
- // -> ['Sword', 'Watch']
57
+ await db .get (" userInfo.balance" ); // -> 1000
58
+ await db .get (" userInfo.items" ); // -> ['Sword', 'Watch']
71
59
72
60
// remove item
73
61
db .pull (" userInfo" , " Sword" , " items" ).then (console .log );
74
62
// -> { difficulty: 'Easy', items: ['Watch'], balance: 1000 }
75
63
}
76
64
```
77
65
66
+ ** Created and maintained by CesiumLabs**
67
+
78
68
# Discord Support
79
- ** [ SnowflakeDev Community ❄️ ] ( https://snowflakedev.org/discord ) **
69
+ ** [ CesiumLabs ] ( https://discord.gg/uqB8kxh ) **
0 commit comments