edwardhotchkiss / mongoose-paginate

Mongoose.js (Node.js & MongoDB) Document Query Pagination
MIT License
984 stars 216 forks source link

how to define what keys I need to return? #30

Closed maggie03230 closed 9 years ago

maggie03230 commented 10 years ago

When I'm using mongoose, I can find and return the keys I need, just like: myModel.find(null,{name:true}) and the data come back will be[ {_id:xxx,name:xxx},{_id:yyy,name:yyy}] ……just like that. can mongoose-paginate also return specific keys I need?

niftylettuce commented 9 years ago

You mean .select like querying? Sure just pass it as options.

ccnokes commented 9 years ago

I've been trying to pass select options like so:

    Article.paginate(
        { 
            status: 'active'
        }, 
        {
            select: 'title teaser createdDate status _id slug',
            page: page, 
            limit: limit,
            sortBy: {
                createdDate: -1
            }
        }, 
        paginateCb
    );

That doesn't seem to be working and I've tried a few variations on the select property, such as {title:-1}. Am I missing something?

ccnokes commented 9 years ago

Oh just kidding, just got it working using the columns property like so:

    Article.paginate(
        { 
            status: 'active'
        }, 
        {
            columns: 'title teaser createdDate status _id slug',
            page: page, 
            limit: limit,
            sortBy: {
                createdDate: -1
            }
        }, 
        paginateCb
    );