Skip to content

Instantly share code, notes, and snippets.

@jrodl3r
Created November 1, 2019 20:56
Show Gist options
  • Save jrodl3r/484a97e913916591370ce641a4a9c1f1 to your computer and use it in GitHub Desktop.
Save jrodl3r/484a97e913916591370ce641a4a9c1f1 to your computer and use it in GitHub Desktop.
ElasticSearch - Seed Firebase Data
const admin = require('firebase-admin');
const faker = require('faker');
const serviceAccount = require('../tmp/serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();
const seedContacts = () => {
faker.locale = 'en_US';
const id = faker.random.uuid().substr(0, 6);
return db.collection('contacts').doc(`${id}XXXX`).set({
address1: faker.address.streetAddress(),
address2: `${faker.address.city()}, ${faker.address.state()} ${faker.address.zipCode()}`,
email: faker.internet.email(),
company: faker.company.companyName(),
created: faker.date.recent(),
id: `${id}XX`,
lastEdited: faker.date.recent(),
name: `${faker.name.firstName()} ${faker.name.lastName()}`,
phone: faker.phone.phoneNumberFormat(),
tagLine: faker.name.jobTitle(),
title: faker.name.jobType(),
uid: `${id}XXXX`,
website: faker.internet.url()
})
.then(() => console.log(`${id} Created`))
.catch(err => console.log(err));
}
Array(5).fill(0).forEach(seedContacts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment