从Google Datastore获取所有实体

时间:2021-03-24 17:13:46

I "stole" this example from Google documentation:

我从Google文档中“窃取”了这个示例:

function listTasks() {
  const query = datastore.createQuery('Task').order('created');

  datastore
    .runQuery(query)
    .then(results => {
      const tasks = results[0];

      console.log('Tasks:');
      tasks.forEach(task => {
        const taskKey = task[datastore.KEY];
        console.log(taskKey.id, task);
      });
    })
    .catch(err => {
      console.error('ERROR:', err);
    });
}

It didn't work at first but after I found an answer on SO about login thingy now I see some results. The problem is... I am trying to display all the entities from 1 collection. Collection called "Tasks" since it was also taken from the docs. It has only 1 entry right now:

它起初没有用,但是在我找到关于登录的东西的答案之后我现在看到了一些结果。问题是......我试图显示1个集合中的所有实体。集合称为“任务”,因为它也是从文档中获取的。它现在只有1个条目:

从Google Datastore获取所有实体

I see only Tasks: displayed in the console without any information from the actual DB. Is there anything wrong with the official code?

我只看到任务:显示在控制台中,没有来自实际数据库的任何信息。官方代码有什么问题吗?

1 个解决方案

#1


2  

Ok, I am slow. So the problem was that .order('created') isn't a "built-in" functionality, I don't have that property in my collection so nothing to sort by. Weird that it wasn't causing an error because of that, but without it everything worked.

好的,我很慢。所以问题是.order('created')不是“内置”功能,我的集合中没有那个属性,所以没有什么可以排序。奇怪的是它并没有因此而导致错误,但没有它就一切顺利。

#1


2  

Ok, I am slow. So the problem was that .order('created') isn't a "built-in" functionality, I don't have that property in my collection so nothing to sort by. Weird that it wasn't causing an error because of that, but without it everything worked.

好的,我很慢。所以问题是.order('created')不是“内置”功能,我的集合中没有那个属性,所以没有什么可以排序。奇怪的是它并没有因此而导致错误,但没有它就一切顺利。