Reputation:
I have this code inside my FOXX play application
var geodata = new Geodata(
applicationContext.collection('geodata'),
{model: Geodatum}
);
/** Lists of all geodata.
*
* This function simply returns the list of all Geodatum.
*/
controller.get('/', function (req, res) {
var parameters = req.parameters;
var limit = parameters['limit'];
var result = geodata.all().limit(10);
if (limit != "undefined") {
result = result.slice(0, limit);
}
res.json(_.map(result, function (model) {
return model.forClient();
}));
});
According to the docs I should be able to use pagination here - I want to limit the search results by the given 'limit' parameter but this gives me an error
2016-05-16T14:17:58Z [6354] ERROR TypeError: geodata.all(...).limit is not a function
Upvotes: 0
Views: 97
Reputation: 10892
Update: The Simple Queries interface is long deprecated and much more powerful AQL query language should be used instead.
The documentation refers to collections. You seem to be using a Foxx repository. Foxx repositories are wrappers around collections that provide most of the same methods but instead of returning plain documents (or cursors) they wrap the results in Foxx models.
In your case it looks like you probably don't want to use Foxx models at all (you're just converting them back to documents, likely just removing a few attributes like _rev
and _id
) so you could simply forego the repository completely and use the collection you're passing into it directly:
var geodata = applicationContext.collection('geodata');
/** Lists of all geodata.
*
* This function simply returns the list of all Geodatum.
*/
controller.get('/', function (req, res) {
var parameters = req.parameters;
var limit = parameters['limit'];
var result = geodata.all().limit(10);
if (limit != "undefined") {
result = result.slice(0, limit);
}
res.json(_.map(result, function (doc) {
return _.omit(doc, ['_id', '_rev']);
}));
});
You're not the first person to be confused by the distinction between repositories and collections, which is why repositories and models will go away in the upcoming 3.0 release (but you can still use them in legacy 2.8-compatible services if you need to).
Upvotes: 1