关于“Importing Data to a Firestore Database”的评价

关于“Importing Data to a Firestore Database”的评价

32055 条评价

Jiner Q. · 已于 23 days前审核

Yuriy K. · 已于 23 days前审核

Missed info, that database name should stay (default)

Volodymyr G. · 已于 24 days前审核

MOGHAL M. · 已于 24 days前审核

Lawrence Tetteh Q. · 已于 24 days前审核

Esteban Pedro A. · 已于 24 days前审核

does neither recognize created csv nor db creation, can't be finished

León H. · 已于 24 days前审核

DineshKumaran G. · 已于 24 days前审核

Ігор М. · 已于 25 days前审核

Roberto H. · 已于 25 days前审核

Danh N. · 已于 25 days前审核

Pietro P. · 已于 25 days前审核

Kaustubh B. · 已于 25 days前审核

Volodymyr B. · 已于 25 days前审核

code copy paste steps in this example is not beginner friendly

rakesh m. · 已于 25 days前审核

Gerald P. · 已于 26 days前审核

S M. · 已于 26 days前审核

Ivan M. · 已于 26 days前审核

Tomasz P. · 已于 26 days前审核

Mykhailo T. · 已于 26 days前审核

Roberto H. · 已于 27 days前审核

Aurika T. · 已于 27 days前审核

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. · 已于 27 days前审核

Daniel S. · 已于 27 days前审核

Fabio E. · 已于 27 days前审核

我们无法确保发布的评价来自已购买或已使用产品的消费者。评价未经 Google 核实。