在react-redux-firebase中,如何进行类似于firestore文档中所示的批处理写入?(见下文)
// Get a new write batch
var batch = db.batch();
// Set the value of 'NYC'
var nycRef = db.collection("cities").doc("NYC");
batch.set(nycRef, {name: "New York City"});
// Update the population of 'SF'
var sfRef = db.collection("cities").doc("SF");
batch.update(sfRef, {"population": 1000000});
// Delete the city 'LA'
var laRef = db.collection("cities").doc("LA");
batch.delete(laRef);
// Commit the batch
batch.commit().then(function () {
// ...
});发布于 2020-09-10 16:30:52
像这样的东西会起作用的。不要忘记,react-redux-firebase和redux-firestore分别扩展了firebase和firestore的原始实现。
const Counter = () => {
const firestore = useFirestore()
const batch = firestore.batch()
const nycRef = firestore.get({collection: 'cities', doc: 'NYC'})
batch.set(nycRef, {name: 'New York City'})
const sfRef = firestore.get({collection: 'cities', doc: 'SF'})
batch.update(sfRef, {population: 10000000})
const laRef = firestore.get({collection: 'cities', doc: 'LA'})
firestore.delete(laRef)
const runBatch = async () => await batch.commit()
return <button onClick={runBatch}>Attempt Batch</button>
}https://stackoverflow.com/questions/60727502
复制相似问题