Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could not Fetch all records. #39

Open
developerrajtomar opened this issue Mar 1, 2016 · 3 comments
Open

could not Fetch all records. #39

developerrajtomar opened this issue Mar 1, 2016 · 3 comments

Comments

@developerrajtomar
Copy link

I want to get all records present in mongodb database. I've used

var Resource = require('resourcejs');

module.exports = function(app, route) {

// Setup the controller for REST;
Resource(app, '', route, app.models.usermodel).rest();
// Return middleware.
return function(req, res, next) {
next();
};
};

Above is the code on the server side and at client side in angularjs app I've used the below code

angular.module('clientApp')
.controller('UserCtrl', function ($scope, User, $route, logedin, $location) {
if(!logedin){
$location.url('/login');
}
$scope.route = $route;
$scope.users = User.getList().$object;
});

Everything is working fine. But I'm only able to get 10 Results at a time and I can't find a method to get all records in Resourcejs. I want to get all users at a time. Is this possible with Resourcejs or I've to migrate my code to another approach.

@zackurben
Copy link
Contributor

Hi @developerrajtomar,

There are a few things you can do. If you're are using Angulars $http to request the url, you can add a limit query parameter as follows, to the requested url: example.com/endpoint1?limit=999999

Additionally, you can add/change the limit in the Express request object before ResourceJs (or in a before handler to your resourcejs endpoint). For example, if you have some middleware thats being run before you hand the request to resourcejs, you can set the following property req.query.limit = 999999

And as a before handler on one of your endpoints:

Resource(app, '', 'resource', ResourceModel)
    .get({
        before: function(req, res, next) {
            req.query.limit = 999999;
            next();
        }
    })

Let me know if you have any more issues.
Zack

@randallknutson
Copy link
Contributor

Also to clarify, this is something we are planning on making easier in the future. Adding a limit to the querystring will always work but we are trying to figure out a better solution.

@syedsimanta03
Copy link

unable to fetch all data .get() not working with.find('books')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants