gpt4 book ai didi

javascript - 如何从云Firestore中提取非重复文档?

转载 作者:行者123 更新时间:2023-12-01 00:14:50 24 4
gpt4 key购买 nike

因此,目前这些代码用于提取存储在数据库中的文档,我想添加条件来提取某些文档,但不提取重复的文档。

如何编辑代码,以便拉取的任何文档都不会被拉取?

我尝试使用 while 循环,但在这两行上出现了此错误

.then(doc => {

还有

}).catch(err => {

enter image description here

let qnumber = Math.floor((Math.random() * 3) + 1);

agent.add('Question No: ' + count);
count += 1;
const dialogflowAgentDoc = db.collection('esequiz').doc(''+qnumber);

return dialogflowAgentDoc.get()
.then(doc => {
if (!doc.exists) {
agent.add('Question '+qnumber+' not available');
} else {
// agent.add('Quiz Question '+ qnumber);
agent.add(doc.data().question);
let answer = Math.floor(Math.random() * 2) + 1;
if(answer == 1){
agent.add(`1. ` + doc.data().right);
agent.add(`2. ` + doc.data().wrong);
}
else{
agent.add(`1. ` + doc.data().wrong);
agent.add(`2. ` + doc.data().right);
}
agent.add("Which is correct, 1 or 2?");
agent.context.set({
name:'quizanswer',
lifespan: 3,
parameters:{
qnumber:qnumber,
right:answer,
count:count
}
});
}
return Promise.resolve('Read complete');
}).catch(err => {
agent.add('Error reading entry from the Firestore database.');
agent.add('Error: '+ err);
});

最佳答案

There isn't any API to retrieve unique values from Firestore. But you can create a unique id by merging two unique item in your model like and fetch record on it's basis.

extraParm = userID + anyOtherUniqueID

https://medium.com/@jqualls/firebase-firestore-unique-constraints-d0673b7a4952

关于javascript - 如何从云Firestore中提取非重复文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59837909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com