Skip to content

Commit 507ff39

Browse files
committed
Expanded import documentation.
1 parent cf2ed33 commit 507ff39

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,9 @@ If *opts* is set, it must be an object with any of the following properties:
12021202

12031203
* *waitForSync*: Wait until the documents have been synced to disk. Default: `false`.
12041204
* *details*: Whether the response should contain additional details about documents that could not be imported. Default: *false*.
1205-
* *type*: Indicates which format the data uses. Can be `"collection"`, `"array"` or `"auto"`. Default: `"auto"`.
1205+
* *type*: Indicates which format the data uses. Can be `"documents"`, `"array"` or `"auto"`. Default: `"auto"`.
1206+
1207+
If *data* is a JavaScript array, it will be transmitted as a line-delimited JSON stream. If *opts.type* is set to `"array"`, it will be transmitted as regular JSON instead. If *data* is a string, it will be transmitted as it is without any processing.
12061208

12071209
For more information on the *opts* object, see [the HTTP API documentation for bulk imports](https://docs.arangodb.com/HttpBulkImports/ImportingSelfContained.html).
12081210

@@ -1213,16 +1215,40 @@ var db = require('arangojs')();
12131215
db.collection('users', function (err, collection) {
12141216
if (err) return console.error(err);
12151217
collection.import(
1216-
[
1218+
[// document stream
1219+
{username: 'admin', password: 'hunter2', 'favorite-color': 'orange'},
1220+
{username: 'jcd', password: 'bionicman', 'favorite-color': 'black'},
1221+
{username: 'jreyes', password: 'amigo', 'favorite-color': 'white'},
1222+
{username: 'ghermann', password: 'zeitgeist', 'favorite-color': 'blue'}
1223+
],
1224+
function (err, result) {
1225+
if (err) return console.error(err);
1226+
result.created === 4;
1227+
}
1228+
);
1229+
// -- or --
1230+
collection.import(
1231+
[// array stream with header
12171232
['username', 'password', 'favourite_color'],
12181233
['admin', 'hunter2', 'orange'],
12191234
['jcd', 'bionicman', 'black'],
12201235
['jreyes', 'amigo', 'white'],
12211236
['ghermann', 'zeitgeist', 'blue']
12221237
],
1223-
{
1224-
waitForSync: true
1225-
},
1238+
function (err, result) {
1239+
if (err) return console.error(err);
1240+
result.created === 4;
1241+
}
1242+
);
1243+
// -- or --
1244+
collection.import(
1245+
(// raw line-delimited JSON array stream with header
1246+
'["username", "password", "favourite_color"]\r\n' +
1247+
'["admin", "hunter2", "orange"]\r\n' +
1248+
'["jcd", "bionicman", "black"]\r\n' +
1249+
'["jreyes", "amigo", "white"]\r\n' +
1250+
'["ghermann", "zeitgeist", "blue"]\r\n'
1251+
),
12261252
function (err, result) {
12271253
if (err) return console.error(err);
12281254
result.created === 4;

lib/collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ extend(BaseCollection.prototype, {
168168
method: 'POST',
169169
path: 'import',
170170
body: data,
171-
ld: true,
171+
ld: Boolean(opts.type !== 'array'),
172172
qs: extend({}, opts, {collection: this.name})
173173
}, function (err, body) {
174174
if (err) callback(err);

0 commit comments

Comments
 (0)