[Vuejs]-Javascript Firebase Realtime Database typeError: newChildren.insert is not a function

0👍

The error message suggests that there might be an issue with the data being passed to the set() method. Specifically, it seems that the newMessageRef variable is not a valid reference to a location in the Firebase Realtime Database.

Instead of using newMessageRef as the first argument to set(), try passing chatRef.child(newMessageKey) instead. This should create a new child node under the chats/${this.chatId} location with the specified key.

async sendMessage() {
if (this.messageText.trim().length === 0) return;

const chatRef = dbRef(db, `chats/${this.chatId}`);
const snapshot = await get(chatRef);

const newMessageRef = push(chatRef);
const newMessageKey = newMessageRef.key;

const newMessage = {
    id: newMessageKey,
    sender: this.currentUser.uid,
    text: this.messageText.trim(),
    timestamp: serverTimestamp(),
};

console.log("newMessageRef:", newMessageRef);
console.log("newMessage:", newMessage);

await set(chatRef.child(newMessageKey), newMessage);

}

Leave a comment