Currently, I am working on updating a value in a Firestore database document by 1. After some research, I came across the FieldValue.increment(1) method. My objective is to create a form with two fields (Host/Scout) where I can input the name of a person whose host or scout value needs to be incremented. This is the structure of my Vue component:
<template>
<div class="add-wave">
<h3>Add Wave</h3>
<div class="row">
<form @click.prevent="addwave()" class="col s12">
<div class="row">
<div class="input-field col s12">
<input type="text" v-model="host" />
<label class="active">Host</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input type="text" v-model="scout" />
<label class="active">Scout</label>
</div>
</div>
<button type="submit" class="btn">Submit</button>
<router-link to="/member" class="btn grey">Cancel</router-link>
</form>
</div>
</div>
</template>
<script>
import db from "../data/firebaseInit";
export default {
data() {
return {
host: null,
scout: null
};
},
methods: {
addwave() {
db.collection("members")
.where("name", "==", this.$route.params.host)
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
doc.ref
.update({
host: db.FieldValue.increment(1)
})
.then(() => {
this.$router.push({
name: "member",
params: { name: this.name }
});
});
});
});
}
}
};
</script>
Although everything seems to compile fine, I encounter an error when I try to enter a name in each input field - "FirebaseError: 'Function Query.where() requires a valid third argument, but it was undefined'."
I'm unsure why this error is occurring and how I can resolve it. Any guidance in the right direction would be greatly appreciated.