diff --git a/lib/datastore/query.js b/lib/datastore/query.js index 40939cde3a5..8f6a968f116 100644 --- a/lib/datastore/query.js +++ b/lib/datastore/query.js @@ -180,16 +180,20 @@ Query.prototype.groupBy = function(fieldNames) { * * *[More information on projection queries](http://goo.gl/EfsrJl).* * - * @param {array} fieldNames - Properties to return from the matched entities. + * @param {string|string[]} fieldNames - Properties to return from the matched + * entities. * @return {module:datastore/query} * * @example + * // Only retrieve the name property. + * var selectQuery = companyQuery.select('name'); + * * // Only retrieve the name and size properties. * var selectQuery = companyQuery.select(['name', 'size']); */ Query.prototype.select = function(fieldNames) { var query = extend(new Query(), this); - query.selectVal = fieldNames; + query.selectVal = util.arrayize(fieldNames); return query; }; diff --git a/test/datastore/query.js b/test/datastore/query.js index ab8883978d3..db26f5f35fd 100644 --- a/test/datastore/query.js +++ b/test/datastore/query.js @@ -63,6 +63,12 @@ describe('Query', function() { assert.equal(query.selectVal[1], 'title'); }); + it('should support single field selection by field name', function() { + var query = new Query(['kind1']) + .select('name'); + assert.equal(query.selectVal[0], 'name'); + }); + it('should support ancestor filtering', function() { var query = new Query(['kind1']) .hasAncestor(['kind2', 123]);