Skip to content

Instantly share code, notes, and snippets.

@Aschen
Created August 22, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aschen/d10bbb2f45bfea6e5ebe36833e68dc84 to your computer and use it in GitHub Desktop.
Save Aschen/d10bbb2f45bfea6e5ebe36833e68dc84 to your computer and use it in GitHub Desktop.
Code for PR admin-console#434
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