【问题标题】:Is order preserved in Arrays/ListValues in Google Cloud Datastore?订单是否保留在 Google Cloud Datastore 的 Arrays/ListValues 中?
【发布时间】:2019-01-31 21:40:09
【问题描述】:

当我在 Google Cloud Datastore 中存储具有某种数组类型属性的实体并稍后检索它时,似乎数组属性内的值顺序始终以保存方式保留,例如:

// just some key where we save and retrieve our test entity
let key = datastore.key({
  namespace: 'whatever',
  path: ['ArrayTest', 'something']
});

// save an array of numbers in order
let numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
await datastore.save({key, data: {numbers}}); 

// ...

// retrieve that entity later:
let entity = await datastore.get(key);

console.log(entity.numbers);
/* prints out:
 * [ 'zero',
 * 'one',
 * 'two',
 * 'three',
 * 'four',
 * 'five',
 * 'six',
 * 'seven',
 * 'eight',
 * 'nine',
 * 'ten' ]
 */

我只做过这样的小测试,最多有几百个实体,只需保存并获取。到目前为止,我还没有看到检索到的数组的顺序与我保存它的方式不同的情况。 但我不确定这是否得到保证。我在文档中找不到明确说明数组/列表值的顺序以它们的保存方式保留的声明。

我希望以这种方式保持秩序这一假设为依据。

有人可以确认或拒绝这个假设吗?

【问题讨论】:

    标签: node.js google-cloud-platform google-cloud-datastore


    【解决方案1】:

    这是ArrayValue 的文档

    “如果该数组包含索引值和未索引值的混合,则可能不会保留该数组的顺序。”

    这意味着价值顺序被保留——如果你发现它没有提交错误的情况。

    【讨论】:

      猜你喜欢
      • 2020-01-22
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 2021-10-01
      • 2020-12-30
      • 2023-03-20
      相关资源
      最近更新 更多