Skip to content

Commit 90bad53

Browse files
committed
Examples. More.
1 parent a36f84a commit 90bad53

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

README.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,46 +1093,186 @@ See [the HTTP API documentation](https://docs.arangodb.com/HttpCollection/Gettin
10931093

10941094
Retrieves the collection's properties.
10951095

1096+
*Examples*
1097+
1098+
```js
1099+
var db = require('arangojs')();
1100+
db.collection('some-collection', function (err, collection) {
1101+
if (err) return console.error(err);
1102+
collection.properties(function (err, props) {
1103+
if (err) return console.error(err);
1104+
// props contains the collection's properties
1105+
});
1106+
});
1107+
```
1108+
10961109
#### collection.count(callback)
10971110

10981111
Retrieves the number of documents in a collection.
10991112

1113+
*Examples*
1114+
1115+
```js
1116+
var db = require('arangojs')();
1117+
db.collection('some-collection', function (err, collection) {
1118+
if (err) return console.error(err);
1119+
collection.count(function (err, count) {
1120+
if (err) return console.error(err);
1121+
// count contains the collection's count
1122+
});
1123+
});
1124+
```
1125+
11001126
#### collection.figures(callback)
11011127

11021128
Retrieves statistics for a collection.
11031129

1130+
*Examples*
1131+
1132+
```js
1133+
var db = require('arangojs')();
1134+
db.collection('some-collection', function (err, collection) {
1135+
if (err) return console.error(err);
1136+
collection.figures(function (err, figures) {
1137+
if (err) return console.error(err);
1138+
// figures contains the collection's figures
1139+
});
1140+
});
1141+
```
1142+
11041143
#### collection.revision(callback)
11051144

11061145
Retrieves the collection revision ID.
11071146

1147+
*Examples*
1148+
1149+
```js
1150+
var db = require('arangojs')();
1151+
db.collection('some-collection', function (err, collection) {
1152+
if (err) return console.error(err);
1153+
collection.revision(function (err, revision) {
1154+
if (err) return console.error(err);
1155+
// revision contains the collection's revision
1156+
});
1157+
});
1158+
```
1159+
11081160
#### collection.checksum([opts,] callback)
11091161

11101162
Retrieves the collection checksum.
11111163

1164+
For information on the possible options see [the HTTP API for getting collection information](https://docs.arangodb.com/HttpCollection/Getting.html).
1165+
1166+
*Examples*
1167+
1168+
```js
1169+
var db = require('arangojs')();
1170+
db.collection('some-collection', function (err, collection) {
1171+
if (err) return console.error(err);
1172+
collection.checksum(function (err, checksum) {
1173+
if (err) return console.error(err);
1174+
// checksum contains the collection's checksum
1175+
});
1176+
});
1177+
```
1178+
11121179
### Manipulating the collection
11131180

1181+
These functions implement [the HTTP API for modifying collections](https://docs.arangodb.com/HttpCollection/Modifying.html).
1182+
11141183
#### collection.load([count,] callback)
11151184

11161185
Tells the server to load the collection into memory.
11171186

11181187
If *count* is set to `false`, the return value will not include the number of documents in the collection (which may speed up the process).
11191188

1189+
*Examples*
1190+
1191+
```js
1192+
var db = require('arangojs')();
1193+
db.collection('some-collection', function (err, collection) {
1194+
if (err) return console.error(err);
1195+
collection.load(false, function (err) {
1196+
if (err) return console.error(err);
1197+
// the collection has now been loaded into memory
1198+
});
1199+
});
1200+
```
1201+
11201202
#### collection.unload(callback)
11211203

11221204
Tells the server to remove the collection from memory.
11231205

1206+
*Examples*
1207+
1208+
```js
1209+
var db = require('arangojs')();
1210+
db.collection('some-collection', function (err, collection) {
1211+
if (err) return console.error(err);
1212+
collection.unload(function (err) {
1213+
if (err) return console.error(err);
1214+
// the collection has now been unloaded from memory
1215+
});
1216+
});
1217+
```
1218+
11241219
#### collection.setProperties(properties, callback)
11251220

11261221
Replaces the properties of the collection.
11271222

1223+
For information on the *properties* argument see [the HTTP API for modifying collections](https://docs.arangodb.com/HttpCollection/Modifying.html).
1224+
1225+
*Examples*
1226+
1227+
```js
1228+
var db = require('arangojs')();
1229+
db.collection('some-collection', function (err, collection) {
1230+
if (err) return console.error(err);
1231+
collection.setProperties({waitForSync: true}, function (err, result) {
1232+
if (err) return console.error(err);
1233+
result.waitForSync === true;
1234+
// the collection will now wait for data being written to disk
1235+
// whenever a document is changed
1236+
});
1237+
});
1238+
```
1239+
11281240
#### collection.rename(name, callback)
11291241

11301242
Renames the collection. The *Collection* instance will automatically update its name according to the server response.
11311243

1244+
*Examples*
1245+
1246+
```js
1247+
var db = require('arangojs')();
1248+
db.collection('some-collection', function (err, collection) {
1249+
if (err) return console.error(err);
1250+
collection.rename('new-collection-name', function (err, result) {
1251+
if (err) return console.error(err);
1252+
result.name === 'new-collection-name';
1253+
collection.name === result.name;
1254+
// result contains additional information about the collection
1255+
});
1256+
});
1257+
```
1258+
11321259
#### collection.rotate(callback)
11331260

11341261
Rotates the journal of the collection.
11351262

1263+
*Examples*
1264+
1265+
```js
1266+
var db = require('arangojs')();
1267+
db.collection('some-collection', function (err, collection) {
1268+
if (err) return console.error(err);
1269+
collection.rotate(function (err, result) {
1270+
if (err) return console.error(err);
1271+
// result.result will be true if rotation succeeded
1272+
});
1273+
});
1274+
```
1275+
11361276
#### collection.truncate(callback)
11371277

11381278
Deletes **all documents** in the collection in the database.

0 commit comments

Comments
 (0)