Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 当我有额外的where()条件和不等式时,如何从firestore集合中获取随机文档?_Node.js_Firebase_Google Cloud Firestore_Firebase Admin - Fatal编程技术网

Node.js 当我有额外的where()条件和不等式时,如何从firestore集合中获取随机文档?

Node.js 当我有额外的where()条件和不等式时,如何从firestore集合中获取随机文档?,node.js,firebase,google-cloud-firestore,firebase-admin,Node.js,Firebase,Google Cloud Firestore,Firebase Admin,我正试图编写一个nodejs云函数,从firestore中的“profiles”集合中获取一个随机文档,如下所示: randomProfile = await admin.firestore().collection('profiles') .where('fieldA', '==', ...) .where('fieldB', '==', ...) .where('fieldC', '==' ...) .where('fieldD', '==',...) .where('fieldE', '&

我正试图编写一个nodejs云函数,从firestore中的“profiles”集合中获取一个随机文档,如下所示:

randomProfile = await admin.firestore().collection('profiles')
.where('fieldA', '==', ...)
.where('fieldB', '==', ...)
.where('fieldC', '==' ...)
.where('fieldD', '==',...)
.where('fieldE', '<=', ...)
.where('fieldE', '>=', ...)
.offset(random)
.limit(1)
.get()
randomProfile=wait admin.firestore()集合('profiles'))
.where('fieldA','=',…)
.where('fieldB','=',…)
.where('fieldC','='='…)
.where('fieldD','=',…)
.where('fieldE','=',…)
.偏移量(随机)
.限额(1)
.get()
由于我使用了
=
字段的
=
,而且firestore允许打开,所以我尝试使用offset子句来获取随机文档

我的问题是:如何为
random
分配一个值,使我没有“越界”条件?换句话说,我不希望
random
大于查询可以返回的文档数

请帮忙!在我当前的项目中继续使用firestore,这是一个成败攸关的问题,我已经走得太远了


注意:由于
fieldE
问题,我无法使用。我在帖子的最后一行链接了这个答案。也许你错过了它,为什么它对我不起作用。非常抱歉,我得告诉你我是怎么错过的。