How to get the full key from the returned ancestor request object in google store?

I am using an ancestor request to retrieve an object from google repository using nodejs

query = datastore.createQuery(entity).hasAncestor(key)

where is the key

key = datastore.key([kind_name_of_parent, id_of_parent])

I can get the objects, but I would like to get the full key of the restored object, while the returned array contains only the returned objects and endCursor.

How can I get the full key? or, can I get the full key from endCursor?

An example of my query result:

[{ modTS: 1481006473081, modLoc: null, modUid: 0, createTS: 1481006473081 } ], { moreResults: 'NO_MORE_RESULTS', endCursor: 'CloSVGoTc350ZXN0cHJvamVjdC0zN2ZiNnI9CxIEdXNlchiAgID409OICgw‌​LEgRzaW1zGICAgICAgIA‌​KDAsSDmNsaWVudFNldHR‌​wsdrfGICAgICA5NEKDBg‌​AIAA=' } ]

+4
source share
3 answers

datastore client v0.42.2, Symbol datastoreClient.KEY.

CLI, , ( - " " ).

'use strict';

const Datastore = require('@google-cloud/datastore'),
    projectId = 'your-project-id',
    datastore = Datastore({
        projectId: projectId
    }),
    pkind = 'Foo',
    pname = 'foo',
    kind = 'Bar',
    name = 'bar',
    parentKey = datastore.key([pkind, pname ]),
    entityKey = datastore.key([pkind, pname, kind, name]),
    entity = {
        key: entityKey,
        data: {
            propa: 'valuea'
        }
    },
    query = datastore.createQuery().hasAncestor(parentKey).limit(5);

let complete = false;

datastore.save(entity).then(() => {
    datastore.runQuery(query).then((res) => {
        try {
            console.log('parent key ', res[0][0][datastore.KEY].parent);
        } finally {
            complete = true;
        }
    });

});

function waitUntilComplete() {
    if (!complete)
        setTimeout(waitUntilComplete, 1000);
}

waitUntilComplete();
+2

SDK .

key, JSON .

Symbols, ES6.

entity[datastoreClient.KEY], , datastoreClient / SDK .

+2

Keys were received: res[0][0][datastore.KEY]

+1
source

Source: https://habr.com/ru/post/1662968/


All Articles