title: How to do a "keys-only-query" in Google Cloud Datastore (Node.js)
body: <p>I am trying to do a "keys-only query" with Google Datastore API for Node.js, as exemplified in the documentation <a href="https://cloud.google.com/datastore/docs/concepts/queries#datastore-keys-only-query-nodejs" rel="noreferrer">here</a>.</p>
  
  <p>I do that after having saved a number of records like this:</p>
  
  <pre><code>datastore.save(
    records.map(
      (record) =&gt; {
        return {
          key: datastore.key([kind, record.id]),
          data: record,
        };
      }
    )
  </code></pre>
  
  <p>The constant <code>kind</code> is a string. Each <code>record</code> has a valid unique <code>id</code> property (a number), which, as shown here, should also serve as the datastore key identifier.</p>
  
  <p>The records are stored correctly. I can retrieve them all without problems through</p>
  
  <pre><code>datastore.runQuery(datastore.createQuery(kind))
  .then( (results) =&gt; {
      // whatever...
  }
  </code></pre>
  
  <p>All the saved records are returned correctly.</p>
  
  <p>But when I do a "keys-only query" like this (and <a href="https://cloud.google.com/datastore/docs/concepts/queries#datastore-keys-only-query-nodejs" rel="noreferrer">as exemplified in the documentation</a>):</p>
  
  <pre><code>const query = datastore.createQuery(kind)
    .select('__key__');
  datastore.runQuery(query)
  .then( (results) =&gt; {
      // whatever...
  }
  </code></pre>
  
  <p>my <code>results[0]</code> return value is simply an array of empty objects like this:</p>
  
  <pre><code>results[0]: [ {}, {}, {}, {}, {}, ..., {}]
  </code></pre>
  
  <p>The number of empty objects returned here is the correct number of records of the given kind. But the problem is that they are empty objects. I expected to get the datastore key for each record here.</p>
  
  <p>If, on the other hand, I do a "normal" projection query, on a "normal" property (like "id" - which should be identical with the datastore key, as far as I understand, after having defined the key through <code>datastore.key[kind, record.id]</code>), I retrieve the projected "id" properties correctly thus:</p>
  
  <pre><code>const query = datastore.createQuery(kind)
    .select('id');
  datastore.runQuery(query)
  .then( (results) =&gt; {
      // whatever...
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>results[0]: [ 
    { id: 5289385927 },
    { id: 5483575687 },
    { id: 5540575111 },
    { id: 5540622279 },
    // ... and so on
  ]
  </code></pre>
  
  <p>So what is wrong with my "keys-only-query"? I have done it exactly in the way the documentation describes. But I get only empty results.</p>
  
  <p><strong>NOTE:</strong> <s>I have tested this only in Datastore emulator.</s> Same result in Datastore Emulator as in AppEngine.</p>