Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.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
Javascript Firestore,其中带有参数的查询不起作用_Javascript_Firebase_Google Cloud Firestore - Fatal编程技术网

Javascript Firestore,其中带有参数的查询不起作用

Javascript Firestore,其中带有参数的查询不起作用,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我有一个查询没有像我期望的那样工作。我有一个名为“游戏”的收藏,里面有很多文档。 每个文档都有一个名为“hiScores”的数组,该数组由该轮的结果组成。我想查询特定玩家的所有游戏,例如: .where('hiScores.playerName', '==', 'David Lamm') 这并没有归还任何东西。我在查询文档中的顶级变量时没有问题。我做错了什么 数据库: 问题是hiScores字段是一个数组,而不是一个对象。您可以判断它是一个数组,因为屏幕截图中数组的第一个立即数元素的索引为0

我有一个查询没有像我期望的那样工作。我有一个名为“游戏”的收藏,里面有很多文档。 每个文档都有一个名为“hiScores”的数组,该数组由该轮的结果组成。我想查询特定玩家的所有游戏,例如:

.where('hiScores.playerName', '==', 'David Lamm')
这并没有归还任何东西。我在查询文档中的顶级变量时没有问题。我做错了什么

数据库:


问题是hiScores字段是一个数组,而不是一个对象。您可以判断它是一个数组,因为屏幕截图中数组的第一个立即数元素的索引为0。您试图查询他的核心,就好像它是一个具有一个名为playerName的属性的单个对象一样


Firestore不支持在数组字段中查询对象属性。如果您有一个数组字段,则只能通过查询来查找整个项目存在于数组中的文档(查询)。

问题在于hiScores字段是一个数组,而不是一个对象。您可以判断它是一个数组,因为屏幕截图中数组的第一个立即数元素的索引为0。您试图查询他的核心,就好像它是一个具有一个名为playerName的属性的单个对象一样


Firestore不支持在数组字段中查询对象属性。如果您有一个数组字段,则只能通过查询来查找数组中存在整个项目的文档(查询)。

正如Doug所指出的,这在firestore中目前是不可能的


您可以在每个名为playerNames[]的游戏中创建顶级字符串数组。然后在带有数组_contains的playerNames上使用where条件。

正如Doug所指出的,这在firestore中目前是不可能的

您可以在每个名为playerNames[]的游戏中创建顶级字符串数组。然后在带有数组_contains的playerNames上使用where条件

db.collection('games')
  .where('hiScores.playerName', '==', 'David Lamm')
  .get()
  .then(function(querySnapshot) {
    console.log('Davids games:')

    querySnapshot.forEach(function(doc) {
      console.log(doc.id, " => ", doc.data());
    });
  })
  .catch(function(error) {
    console.log("Error getting documents: ", error);
  }
);