Importing Data to a Firestore Database Ulasan

Importing Data to a Firestore Database Ulasan

32320 ulasan

Danh N. · Diulas 2 bulan lalu

Pietro P. · Diulas 2 bulan lalu

Kaustubh B. · Diulas 2 bulan lalu

Volodymyr B. · Diulas 2 bulan lalu

code copy paste steps in this example is not beginner friendly

rakesh m. · Diulas 2 bulan lalu

Gerald P. · Diulas 2 bulan lalu

S M. · Diulas 2 bulan lalu

Ivan M. · Diulas 2 bulan lalu

Tomasz P. · Diulas 2 bulan lalu

Mykhailo T. · Diulas 2 bulan lalu

Roberto H. · Diulas 2 bulan lalu

Aurika T. · Diulas 2 bulan lalu

const { promisify } = require('util'); const { parse } = require('csv-parse'); const { readFile } = require('fs').promises; const { Firestore } = require('@google-cloud/firestore'); const { Logging } = require('@google-cloud/logging'); const logName = 'pet-theory-logs-importTestData'; const logging = new Logging(); const log = logging.log(logName); const resource = { type: 'global', }; if (process.argv.length < 3) { console.error('Please include a path to a csv file'); process.exit(1); } const db = new Firestore(); const parseCsv = promisify(parse); async function writeToFirestore(records) { const batchCommits = []; let batch = db.batch(); records.forEach((record, i) => { const docRef = db.collection('customers').doc(record.email); batch.set(docRef, record); if ((i + 1) % 500 === 0) { console.log(`Writing record ${i + 1}`); batchCommits.push(batch.commit()); batch = db.batch(); } }); batchCommits.push(batch.commit()); return Promise.all(batchCommits); } function writeToDatabase(records) { records.forEach((record, i) => { console.log(`ID: ${record.id} Email: ${record.email} Name: ${record.name} Phone: ${record.phone}`); }); } async function importCsv(csvFileName) { const fileContents = await readFile(csvFileName, 'utf8'); const records = await parseCsv(fileContents, { columns: true }); try { await writeToFirestore(records); //await writeToDatabase(records); } catch (e) { console.error(e); process.exit(1); } console.log(`Wrote ${records.length} records`); const success_message = `Success: importTestData - Wrote ${records.length} records`; const entry = log.entry({ resource: resource }, { message: `${success_message}` }); log.write([entry]); } importCsv(process.argv[2]).catch(e => console.error(e));

SRITAM B. · Diulas 2 bulan lalu

Daniel S. · Diulas 2 bulan lalu

Fabio E. · Diulas 2 bulan lalu

Razvan S. · Diulas 2 bulan lalu

Aurika T. · Diulas 2 bulan lalu

Pablo G. · Diulas 2 bulan lalu

nilesh k. · Diulas 2 bulan lalu

Dmytro C. · Diulas 2 bulan lalu

Olena V. · Diulas 2 bulan lalu

Saad Ahmed K. · Diulas 2 bulan lalu

Julio C. · Diulas 2 bulan lalu

Nice

Atul P. · Diulas 2 bulan lalu

Andrii M. · Diulas 2 bulan lalu

Kami tidak dapat memastikan bahwa ulasan yang dipublikasikan berasal dari konsumen yang telah membeli atau menggunakan produk terkait. Ulasan tidak diverifikasi oleh Google.