简体   繁体   English

Google Cloud Datastore 中的 Arrays/ListValues 中是否保留了顺序?

[英]Is order preserved in Arrays/ListValues in Google Cloud Datastore?

When I store an entity in Google Cloud Datastore with some property of type array, and I retrieve it later, it seems the order of values inside the array property is always preserved in the way it was saved, eg:当我在 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' ]
 */

I have only done small tests like this, with up to a few hundred entities and simply save and get.我只做过这样的小测试,最多有几百个实体,只需保存和获取。 So far I have not seen a case where the retrieved array is ordered differently from how I saved it.到目前为止,我还没有看到检索到的数组的排序方式与我保存它的方式不同的情况。 But I am not sure if this is guaranteed.但我不确定这是否有保证。 I could not find a statement in the docs stating explicitly that order of arrays / list values is preserved in the way they are saved.我在文档中找不到明确说明数组/列表值的顺序以保存方式保留的语句。

I would like to rely on the assumption that order is preserved in that way.我想依赖于以这种方式保留订单的假设。

Can someone confirm or reject this assumption?有人可以确认或拒绝这个假设吗?

Here are the docs for ArrayValue这是ArrayValue的文档

"The order of this array may not be preserved if it contains a mix of indexed and unindexed values." “如果该数组包含索引值和未索引值的混合,则可能无法保留该数组的顺序。”

This means that value order is preserved -- if you find a case where it isn't file a bug.这意味着值顺序被保留——如果你发现它不是提交错误的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM