-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnew.jsx
57 lines (51 loc) · 2.32 KB
/
new.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// import React, { useState } from 'react';
// import firebase from './firebase';
// // import 'firebase/firestore';
// const UpdateDocumentByFieldValue = () => {
// const [collection, setCollection] = useState('');
// const [fieldName, setFieldName] = useState('');
// const [fieldValue, setFieldValue] = useState('');
// const [errorMessage, setErrorMessage] = useState('');
// const handleUpdate = async (e) => {
// e.preventDefault();
// if (!collection || !fieldName || !fieldValue) {
// setErrorMessage('Please fill in all fields.');
// return;
// }
// const db = firebase.firestore();
// const querySnapshot = await db.collection(collection).where(fieldName, '==', fieldValue).get();
// querySnapshot.forEach(async (doc) => {
// try {
// await db.collection(collection).doc(doc.id).update({
// [fieldName]: 'NEW_VALUE_HERE'
// });
// console.log(`Document with ID ${doc.id} updated successfully`);
// } catch (error) {
// console.error(`Error updating document with ID ${doc.id}:`, error);
// setErrorMessage(`Error updating document with ID ${doc.id}: ${error.message}`);
// }
// });
// };
// return (
// <div>
// <h2>Update Document By Field Value</h2>
// <form onSubmit={handleUpdate}>
// <label>
// Collection Name:
// <input type="text" value={collection} onChange={(e) => setCollection(e.target.value)} />
// </label>
// <label>
// Field Name:
// <input type="text" value={fieldName} onChange={(e) => setFieldName(e.target.value)} />
// </label>
// <label>
// Field Value:
// <input type="text" value={fieldValue} onChange={(e) => setFieldValue(e.target.value)} />
// </label>
// <button type="submit">Update Document</button>
// {errorMessage && <p>{errorMessage}</p>}
// </form>
// </div>
// );
// };
// export default UpdateDocumentByFieldValue;