firestore updateDoc removes other fields in array [duplicate] - javascript

This question already has answers here:
How to update array elements in Firestore with Android?
(2 answers)
How to update an array item in Firestore
(2 answers)
Firestore Update single item in an array field
(2 answers)
Closed 11 months ago.
async function editBackEnd() {
const entryRef = doc(db, "accounts", user.uid)
await updateDoc(entryRef, {
"entry.0.payment": "League"
})
}
I'm trying to update certain fields in an array in firestore. I know there is no direct way to do so but with this code i am able to access the field but it removes all the other entries/fields.
How do I make sure it only updates the field that i want. in this cause im just trying to update payment of index 0
Im having issues uploading pics to stackoverlow so here's a couple url
https://imgur.com/a/1hqNgsn firestore database before updateDoc
https://imgur.com/a/Egzofvz firestore database after updateDoc

Related

How can i update an item in an array on firebase [duplicate]

This question already has answers here:
Firestore Update single item in an array field
(2 answers)
How can I update an object inside of an array in firestore?
(1 answer)
Closed 6 months ago.
I'm trying to make a button that can edit an item within a documents array in firebase. Basically, the functionality I'm building is: you click an EDIT button, and it changes a tag into an tag where you would make your edit/update to the array item. Then you would click a DONE button and the update to the array would happen. For some reason, I can only find documentation on firebase for updating a document, and not an item inside the array. I've tried using arrayUnion but it only adds a new item to the array. I'm trying to update the info[0].tags in the screenshot below. Please let me know if I'm missing information to help make this work.
My issue seems to be I can't do: info[i]: arrayUnion({tags: tags}) so I'm not sure how to tell the updateDoc function which item in the info array I need to update.
Here's the code:
const editCard = async (tags, i) => {
const fieldRef = doc(db, "labels", activeLabels);
await updateDoc(fieldRef, {
info[i]: arrayUnion({ tags: tags }),
});
console.log(tags);
getLabels();
findLabel(activeLabels);
toast.success("Tags Updated!");
};
[![firebase document and array][1]][1]
[1]: https://i.stack.imgur.com/PDJcc.png

how to make a query to access a map that is inside an array in FireStore? JavaScript [duplicate]

This question already has answers here:
Firestore to query by an array's field value
(3 answers)
How to apply filter on an array in a collection in firestore
(1 answer)
Closed 6 months ago.
How to perform query filtering on values ​​of a map nested inside an array field?
const empleado = collection(db, "empleados");
const q = query(empleado, where('solicitudAusencia', 'array-contains',''))onSnapshot(q,(snapshot)=>{
let empleados=[]
let total=[]
snapshot.forEach(doc=>{
empleados.push({...doc.data()})
})
console.log(empleados)

How to get this subcollection's ref id in firestore [duplicate]

This question already has answers here:
Fetching all collections in Firestore
(3 answers)
How to list subcollections in a Cloud Firestore document
(4 answers)
Closed 9 months ago.
I am trying to get this subcollection's ref id
I am following this tutorial however :
[2]: https://www.pluralsight.com/guides/consume-data-from-firebase-firestore-in-a-react-app
I want to get the hBYWvZ3KN3NLLrucTpryeTQZnHz2 from the firestore :
const HighlightDbId = await db.collection('highlights')
.doc('2SCS2S0JnzngWEiYkHNk')
.collection('hBYWvZ3KN3NLLrucTpryeTQZnHz2')
Please how can I possible get that id ??
The code you currently have creates a reference to the collection.
Data won't be loaded from that reference until you call get() or onSnapshot on it, so:
const HighlightDbId = await db.collection('highlights')
.doc('2SCS2S0JnzngWEiYkHNk')
.collection('hBYWvZ3KN3NLLrucTpryeTQZnHz2')
.get()

How to add field to all documents in database mongoose [duplicate]

This question already has answers here:
Add new field to every document in a MongoDB collection
(7 answers)
Closed 1 year ago.
I am trying to add a field to all documents in the database, but I am not sure how to do that. Here is my database
const db = client.schema
How would I update all documents and add a field called tiks (number) in it?
db.yourCollection.update(
{},
{ $set: {"newField": 1} },
false,
true
)
Parameters
Collection to update since you want all {}
Field to set
Upsert - only add when it is not there hence false
Multi - update multiple documents if matches to query hence true

How to get specific value or row data from firebase in web [duplicate]

This question already has answers here:
Firebase search by child value
(2 answers)
Closed 4 years ago.
basically I new to firebase, I just want to that how to retrive specific data from firebase ,
[firabase](https://i.stack.imgur.com/vk0S6.png[1]
as you can see in above image I want to retrieve like in Sql we use
Select CellNum from Student where Email="Adnan#gmail.com.
How can I do that in firebase web javascript?
Try the following:
firebase.database().ref().child("Students").orderByChild("Email").equalTo("Adnan#gmail.com").once("value", function (snapshot) {
snapshot.forEach(function(childSnapshot) {
var cellNum=childSnapshot.val().CellNum;
});
});
The snapshot is at Students, then you loop inside the id 22222 and retrieve the CellNum. The orderByChild is the query where Email="Adnan#gmail.com"

Categories