I have a collection and i want to both create document and then add to its arrays values or if document exist only add the values to the arrays. Here what I've tried.
addMessage() {
if(this.message.length < 30 && this.message.length > 10) {
alert('ok')
var new= db.collection("messages").doc(this.alias)
new.set( {
messages: this.message,
date: Date.now()
})
} else {
alert('no')
}
when i use set like above it works BUT i want to add values to array so i try and use add but i get error "new.add is not a function"
new.add()makes very little sense, asnewis aDocumentReference, which doesn't have anaddmethod.newvariable, which is aDocumentReference. To add a message to an existing array of messages, you will need to first load the document, then add the message to the array, and then finally write the result back to the database. See stackoverflow.com/a/48235053 for an example and stackoverflow.com/a/46773121/209103.