使用' gcloud' for node.js我正在尝试使用数据存储区在创建过程中分配给它的唯一密钥ID从数据存储区中检索实体。
我尝试过很多不同的createQuery设置,但都没有。
const kind = 'campaign';
var q = ds.createQuery([kind])
.filter('id', '=', 5672749318012928);
var q = ds.createQuery([kind])
.filter('id', 5672749318012928);
var q = ds.createQuery([kind])
.filter('key', '=', 5672749318012928);
var q = ds.createQuery([kind])
.filter('__key__ =', ['campaign', 5672749318012928]);
var q = ds.createQuery([kind])
.filter('__key__', '=', ['campaign', 5672749318012928]);
我已经使用其中一个属性测试了查询,并且工作正常,返回结果:
const kind = 'campaign';
var q = ds.createQuery([kind])
.filter('campaign_id', '=', 1286372673);
我错过了什么,你真的可以根据其独特的密钥进行过滤吗?
答案 0 :(得分:0)
You should be able to do:
var q = ds.createQuery([kind])
.filter('__key__', '=', ds.key(['campaign', 5672749318012928]));
However, if you are fetching a single entity by its key, the lookup
command is more efficient:
var k = ds.key(['campaign', 5672749318012928])
ds.get(k, function (err, entity) {
...
}
});
https://cloud.google.com/datastore/docs/concepts/entities https://cloud.google.com/datastore/docs/concepts/queries