-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
31 lines (24 loc) · 733 Bytes
/
test.js
File metadata and controls
31 lines (24 loc) · 733 Bytes
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
'use strict';
var db = require('./index.js');
var message = {foo: 'bar'}
// example 1 - not using callbacks
var insert = db('mongodb://localhost/quai');
// wait a bit for db connection
setTimeout(function(){
insert(message);
}, 100);
// =>
// connected to mongoDB mongodb://localhost/quai
// Saved to MongoDB. message: {"foo":"bar","_id":"51a908865dc559285f000001"}
// example 2 - using callbacks
var insert = db('mongodb://localhost/quai', function(err){
if (err) { console.error(err); return 1; };
console.log('Connected.');
insert(message, function(err){
if (err) { console.error(err); return 1; };
console.log('Saved. message: ', message);
});
});
// =>
// Connected.
// Saved. message: { foo: 'bar' }