데이터베이스에 일괄 쓰기를 실행하려고합니다. 그러나이 data[]
오류가 발생하기 때문에 문제가있는 것 같습니다 .
FirebaseError: Expected type 't', but it was: a custom e object
코드:
<template>
<div>
<v-btn @click="setData()">
Write to Firestore
</v-btn>
<router-view/>
</div>
</template>
<script>
import { db } from '@/firebase'
export default {
methods: {
setData() {
var data =
[
{
'title':'Ipsum lorem',
'description':'Some text...',
'color':'#03A9F4',
'meta':
{
'docID':'',
'createdBy':'',
}
},
{
'title':'Loren ipsum',
'description':'Some more text...',
'color':'#06A1F3',
'meta':
{
'docID':'',
'createdBy':'',
}
}
]
var batch = db.batch()
data.forEach((doc) => {
var dbRef = db.collection('teams').doc('team01').collection('templates')
batch.set(dbRef, doc)
})
batch.commit().then(function() {
return console.log("done")
});
}
}
}
</script>
내 파일 data[]
에는 여기에 표시된 것보다 더 많은 개체가 포함되어 있습니다. 500 개 미만입니다. Vuetify를 사용하는 Vue.js 앱에서이 작업을 수행합니다.
meta.docID
있습니까? 일괄 쓰기 작업을 할 수 없습니다.도움을 주시면 감사하겠습니다!
귀하 dbRef
는 CollectionReference 객체입니다.
var dbRef = db.collection('teams').doc('team01').collection('templates')
CollectionReference를에 전달하는 것은 유효하지 않습니다 set()
.
batch.set(dbRef, doc) // this isn't valid
API 문서에서 볼 수 있듯이 set () 에는 첫 번째 인수로 DocumentReference가 대신 필요하므로 문서를 호출하려면 작성할 문서를 식별해야합니다. 즉, 여기에 쓰려면 문서의 고유 ID를 알아 내야합니다. 예를 들면 :
var dbRef = db
.collection('teams')
.doc('team01')
.collection('templates')
.doc("what-is-your-document-id?")
임의의 문서 ID가 필요한 경우 다음 호출에 인수를 제공하지 않아도됩니다 doc()
.
var dbRef = db
.collection('teams')
.doc('team01')
.collection('templates')
.doc()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다