我似乎无法将我在 firestore 中的数据复制到 algolia
I can't seem replicate my data in firestore to algolia
基本上,我正在尝试通过 firebase 云功能将我已经在 firebase 中的数据复制到 algolia 中。代码无法编译,我似乎无法弄清楚原因。
我使用的是打字稿,而不是 javascript,我正在关注这篇文章。
https://medium.com/@soares.rfarias/how-to-set-up-firestore-and-algolia-319fcf2c0d37
我也在VScode
工作
// 这是我文件的顶部
const algoliasearch = require('algoliasearch')
const algoliaClient =
algoliasearch(functions.config().algolia.appid,
functions.config().algolia.apikey)
export const sendCollectionToAlgolia =
functions.https.onRequest(async (req, res) =>
{
const collectionIndex = algoliaClient.initIndex('Organizations')
const db = admin.firestore()
const algoliaRecords = []
const querySnapshot = await db.collection("Organizations").get()
querySnapshot.docs.forEach(doc => {
const document = doc.data()
const record = {
objectID: doc.id,
"orgUsername": document.orgUsername,
"orgName": document.orgName,
"school": document.school
}
algoliaRecords.push(record)
})
collectionIndex.saveObjects(algoliaRecords, (_error: any, content:
any) => {
res.status(200).send("COLLECTION was indexed to Algolia
successfully.");
})
})
我一直收到 "Variable 'algoliaRecords' implicitly has type 'any[]' in some locations where its type cannot be determined" 的编译错误,我不知道如何修复它。我对 algolia 比较陌生,但已经做了一些云功能。
发生这种情况是因为 algoriaRecords
没有明确的类型。通常,TypeScript 会根据您稍后最终分配的内容来推断类型。但是,每个后续 algoriaRecords.push()
操作都会根据添加到变量中的元素演变变量的类型。
一个快速解决这个问题的方法是明确地给 algoriaRecords 一个类型,如下所示:
const algoriaRecords:Object[] = []
此外,您可以让 TypeScript 容忍没有声明类型的参数,请参阅 here 了解更多信息,方法是配置您的 tsconfig.js 文件并将 noImplicitAny 设置为 false,同时删除严格规则 [=15] =]
// "strict": true
"noImplicitAny" : false
基本上,我正在尝试通过 firebase 云功能将我已经在 firebase 中的数据复制到 algolia 中。代码无法编译,我似乎无法弄清楚原因。
我使用的是打字稿,而不是 javascript,我正在关注这篇文章。 https://medium.com/@soares.rfarias/how-to-set-up-firestore-and-algolia-319fcf2c0d37 我也在VScode
工作// 这是我文件的顶部 const algoliasearch = require('algoliasearch')
const algoliaClient =
algoliasearch(functions.config().algolia.appid,
functions.config().algolia.apikey)
export const sendCollectionToAlgolia =
functions.https.onRequest(async (req, res) =>
{
const collectionIndex = algoliaClient.initIndex('Organizations')
const db = admin.firestore()
const algoliaRecords = []
const querySnapshot = await db.collection("Organizations").get()
querySnapshot.docs.forEach(doc => {
const document = doc.data()
const record = {
objectID: doc.id,
"orgUsername": document.orgUsername,
"orgName": document.orgName,
"school": document.school
}
algoliaRecords.push(record)
})
collectionIndex.saveObjects(algoliaRecords, (_error: any, content:
any) => {
res.status(200).send("COLLECTION was indexed to Algolia
successfully.");
})
})
我一直收到 "Variable 'algoliaRecords' implicitly has type 'any[]' in some locations where its type cannot be determined" 的编译错误,我不知道如何修复它。我对 algolia 比较陌生,但已经做了一些云功能。
发生这种情况是因为 algoriaRecords
没有明确的类型。通常,TypeScript 会根据您稍后最终分配的内容来推断类型。但是,每个后续 algoriaRecords.push()
操作都会根据添加到变量中的元素演变变量的类型。
一个快速解决这个问题的方法是明确地给 algoriaRecords 一个类型,如下所示:
const algoriaRecords:Object[] = []
此外,您可以让 TypeScript 容忍没有声明类型的参数,请参阅 here 了解更多信息,方法是配置您的 tsconfig.js 文件并将 noImplicitAny 设置为 false,同时删除严格规则 [=15] =]
// "strict": true
"noImplicitAny" : false