-
-
Save Aschen/d10bbb2f45bfea6e5ebe36833e68dc84 to your computer and use it in GitHub Desktop.
Code for PR admin-console#434
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Bluebird = require('bluebird') | |
const Kuzzle = require('kuzzle-sdk'); | |
const kuzzle = new Kuzzle('localhost', (err, resp) => { | |
const documents = [ | |
['gordon', 'freeman', 'blackmesa', 32], | |
['alyx', 'vance', 'city17', 26], | |
['isaac', 'kleiner', 'blackmesa', 46], | |
['eli', 'vance', 'blackmesa', 53], | |
['barney', 'calhoun', 'city17', 36], | |
['arne', 'magnusson', 'whiteforest', 54], | |
['wallace', 'breen', 'city17', 48] | |
]; | |
kuzzle | |
.createIndexPromise('my-index') | |
.catch(error => console.log(error)) | |
.then(() => kuzzle.collection('my-collection', 'my-index').createPromise()) | |
.catch(error => console.log(error)) | |
.then(() => { | |
return Bluebird.map(documents, ([firstname, lastname, city, age]) => { | |
const document = { | |
firstname, lastname, city, age | |
}; | |
return kuzzle | |
.collection('my-collection', 'my-index') | |
.createDocumentPromise(`${firstname}-${lastname}`, document) | |
}); | |
}) | |
.then(response => console.log(response)) | |
.catch(error => console.log(error)) | |
.finally(() => kuzzle.disconnect()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment