我正在通过Cloud Function将数据从Firebase Firestore导出到MeiliSearch(我是新手),但问题是它正在收集所有数据但在MeiliSearch中它只导出一个块,比如25k中的400个条目,并且通过一次又一次触发该功能导出数据变得越来越少。
meiliSearch 在数字海洋上。
注意:这也让我付出了代价,因为 Firebase 说我已经向 Firestore 发出了 2700 万次调用。
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const axios = require('axios');
const { default: MeiliSearch } = require("meilisearch");
exports.importToMeili = functions.https.onRequest(async (req, res) => {
const config={
host: "http://46.101.197.194",
apiKey: 'My API Key'
}
admin.initializeApp();
const db = admin.firestore();
const userCollection = await db.collection("artikli").get();
const client=new MeiliSearch(config);
const index=0;
for(index;index<24752;index++){
await client.index('artikli').addDocuments([{
objectID: userCollection.docs[index].id,
naziv: userCollection.docs[index].n,
marka: userCollection.docs[index].m,
model: userCollection.docs[index].mo,
katBr: userCollection.docs[index].kb,
id: userCollection.docs[index].id,
cijena: userCollection.docs[index].c,
kolicina: userCollection.docs[index].ko,
lokacija: userCollection.docs[index].l,
opis: userCollection.docs[index].o,
image: userCollection.docs[index].u,
name: userCollection.docs[index].n,
brand: userCollection.docs[index].brand,
price: userCollection.docs[index].c.isEmpty ? 0 : instance.c,
images: userCollection.docs[index].u,
}]);
}
userCollection.docs.map(async doc => {
const instance = doc.data();
await client.index('artikli').addDocuments([{
objectID: doc.id,
naziv: instance.n,
marka: instance.m,
model: instance.mo,
katBr: instance.kb,
id: instance.id,
cijena: instance.c,
kolicina: instance.ko,
lokacija: instance.l,
opis: instance.o,
image: instance.u,
name: instance.n,
brand: instance.brand,
price: instance.c.isEmpty ? 0 : instance.c,
images: instance.u,
}]);
return {
objectID: doc.id,
naziv: instance.n,
marka: instance.m,
model: instance.mo,
katBr: instance.kb,
id: instance.id,
cijena: instance.c,
kolicina: instance.ko,
lokacija: instance.l,
opis: instance.o,
image: instance.u,
name: instance.n,
brand: instance.brand,
price: instance.c.isEmpty ? 0 : instance.c,
images: instance.u,
}
});
await axios.post(
`http://46.101.197.194/indexes/artikli/documents`,
users,
{ headers: { "X-Meili-API-Key": "MY API KEY"} }
)
res.status(200).send()
});
现在,我知道它正在从 firestore 获取整个表数据,但我不知道为什么它不在 meilisearch 中。