-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplan.txt
More file actions
105 lines (78 loc) · 2.24 KB
/
plan.txt
File metadata and controls
105 lines (78 loc) · 2.24 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
1. Put a document in.
/docs/add
This has to be done for any of the CRUD operations:
var marklogic = require('marklogic');
var db = marklogic.createDatabaseClient({
host: 'localhost',
port: '8000',
user: 'admin',
password: 'admin',
authType: 'DIGEST'
});
The first step is to use our DatabaseClient instance (db) to write a document by calling the write() method:
db.documents.write({
uri: '/afternoon-drink',
contentType: 'application/json',
content: {
name: 'Iced Mocha',
size: 'Grand',
tasty: true
}
}).result(function(response) {
console.log(JSON.stringify(response, null, 2));
});
The result will be:
{
"documents": [
{
"uri": "/afternoon-drink",
"contentType": null
}
]
}
1 1/2. Read one document. (Do we have a use for this?)
/docs/retrieve
To get the document back, call the read() method:
db.documents.read({uris: '/afternoon-drink'}).result(…)
1 3/4. Updating a document. (Do we have a user for this?)
Let's don't have a separate operation for this. Just /docs/add again.
Updating (replacing) the document works exactly the same as creating a document: use the write() method.
2. List all the documents.
/docs/list
3. Remove a document.
/docs/remove
To delete the document, call the remove() method:
db.documents.remove('/afternoon-drink').result(…)
4. Find a set of documents that match a set of (not-really-key) words.
/docs/find
To execute any kind of query, call a document instance's query() method and
construct the query using queryBuilder instance qb():
var qb = marklogic.queryBuilder;
db.documents.query(
qb.where(…)
String Query
To run a search that retrieves documents with the word, "delicious":
db.documents.query(
qb.where(
qb.term('delicious')
)).result(…)
If you only want documents with this word that are in your drinks collection, you can do:
db.documents.query(
qb.where(
qb.and(
qb.collection('drinks'),
qb.term('delicious')
)
)).result(…)
From Understanding the queryBuilder Interface:
structured
db.documents.query(
qb.where(
qb.and(qb.term('cat'), qb.term('dog'))
).orderBy(qb.sort('descending')
.slice(0,5)
)
1. Store documents.
2. Delete documents.
3. Query documents.