Node.JS数据存储查询获取密钥 [英] Node.JS Datastore Query get Key

查看:133
本文介绍了Node.JS数据存储查询获取密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取查询返回的实体的键?



我试图像普通数据那样访问它,但是当我在那里打印实体时没有关键。有没有办法做到这一点?



预先感谢您的帮助。 解决方案


$ b

 

var datastore = require('@ google-cloud / datastore')();
var query = datastore.createQuery('AnimalNamespace','Lion');
query.run(function(err,entities){

var keys = entities.map(function(entity){
// datastore.KEY是一个Symbol
返回实体[datastore.KEY];
});
});

您也可以使用gstore-node库( https://github.com/sebelga/gstore-node ),然后你可以通过entity.entityKey直接访问它。

How can I get the key of an entity returned by a query?

I tried to access it like the normal data, but when I print the entity itself there is no key. Is there even a way to do so?

Thank you in advance for your help.

解决方案

Since version 0.5.0 of the @google-cloud/datastore v0.5.0 the key is now accesible by a Symbol.

var datastore = require('@google-cloud/datastore')();
var query = datastore.createQuery('AnimalNamespace', 'Lion');
query.run(function(err, entities) {

var keys = entities.map(function(entity) {
        // datastore.KEY is a Symbol
        return entity[datastore.KEY];
    });
});

You could also use the gstore-node library (https://github.com/sebelga/gstore-node) and then you would access it directly by entity.entityKey

这篇关于Node.JS数据存储查询获取密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆