-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
56 lines (47 loc) · 1.51 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { NodeJSMongoDriver } = require('./index')
const connectionString = `mongodb://user:password@localhost:27017/admin`
const dbHandler = new NodeJSMongoDriver(connectionString)
// or
dbHandler = NodeJSMongoDriver.simple("user", "password", "localhost", 27017, "admin")
dbHandler.query("database", "collection", {
username: "depascaldc"
}, (err, res) => {
if(err) return console.error(err)
if(!res[0]) return console.log("No Objects found in Result...")
console.log(res)
})
dbHandler.queryAsync("database", "collection", {
username: "depascaldc"
}).then(res => {
if(!res[0]) return console.log("No Objects found in Result...")
console.log(res)
}).catch(err=>{
console.error(err)
})
dbHandler.insertObject("database", "collection", {
username: "depascaldc"
}, (err, res) => {
if(err) return console.error(err)
console.log(res) // should be a boolean
})
dbHandler.insertObjectAsync("database", "collection", {
username: "depascaldc"
}).then(res => {
console.log(res) // should be a boolean
}).catch(err=>{
console.error(err)
})
dbHandler.deleteObject("database", "collection", {
username: "depascaldc"
}, (err, res) => {
if(err) return console.error(err)
console.log(res) // should be a boolean
})
dbHandler.deleteObjectAsync("database", "collection", {
username: "depascaldc"
}).then(res => {
console.log(res) // should be a boolean
}).catch(err=>{
console.error(err)
})
// ................. see index.js for more functions... theyre build by the same scheme