const app = tcb.init({
env: 'vue-douyin-test-16f173'
})
app
.auth({ persistance: "session" })
.anonymousAuthProvider()
.signIn()
.then(() => addComment())
.catch(err => console.error(err))
function queryComments() {
const DB = app.database()
DB.collection('comments')
.doc('test')
.get()
.then(res => console.log(res))
}
function addComment() {
const newComment = {
avatar:"/avatar/1.jpg",
date:"4-21",
text:"我是一条评论",
username:"12345"
}
videoId = "test"
const Comments = app.database().collection('comments')
Comments
.doc(videoId)
.get()
.then(res => {
if (res.data.length === 0 ) {
newComment._id = videoId
return Comments.add({
_id: videoId,
comments: [newComment]
})
} else {
return app.callFunction({
name: "docUpdateTest",
data: { newComment, videoId }
})
}
})
.then(res => console.log(res))
}
console