forked from jalalhejazi/jsonfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall.js
61 lines (46 loc) · 1.16 KB
/
all.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
57
58
59
60
61
// in release mode:
// npm install jsonfs
// var db = require('jsonfs');
var db = require('../lib/jsonfs.js');
db.connect('db', ['articles']);
var article = {
title : 'jsonfs works',
published : 'today',
rating : '5 stars'
}
//save
var savedArticle = db.articles.save(article);
console.log(savedArticle);
//findAll
var foundArticles = db.articles.find();
console.log(foundArticles);
foundArticles = db.articles.find({rating : '5 stars'});
console.log(foundArticles);
//findOne
var foundArticles = db.articles.findOne();
console.log(foundArticles);
foundArticles = db.articles.findOne({rating : '5 stars'});
console.log(foundArticles);
//update
var query = {
title : 'jsonfs works'
};
var dataToBeUpdate = {
title : 'jsonfs works again!',
};
var options = {
multi: false,
upsert: false
};
var updated = db.articles.update(query, dataToBeUpdate, options);
console.log(updated);
// after update
foundArticles = db.articles.findOne({rating : '5 stars'});
console.log(foundArticles);
//count
console.log(db.articles.count());
//remove
db.articles.remove({rating : '5 stars'});
db.articles.remove();
// db.articles does not exist anymore!
// run : node all.js