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

mongoose adapter: cannot specify sort direction #38

Closed
TinNT opened this issue Feb 28, 2012 · 6 comments
Closed

mongoose adapter: cannot specify sort direction #38

TinNT opened this issue Feb 28, 2012 · 6 comments

Comments

@TinNT
Copy link

TinNT commented Feb 28, 2012


MongooseAdapter.prototype.all = function all(model, filter, callback) {
   ...
    if (filter.order) {
        query.asc(filter.order); //direction is hardcoded
    }
    ...
};

is there an easy way to patch this issue and define findOne method?

Thanks

@1602
Copy link
Owner

1602 commented Feb 28, 2012

Yep, just need to extend order feature to work with direction option.

Thanks,
Anatoliy

On 28.02.2012, at 10:25, TinNTreply@reply.github.com wrote:


MongooseAdapter.prototype.all = function all(model, filter, callback) {
  ...
   if (filter.order) {
       query.asc(filter.order); //direction is hardcoded
   }
   ...
};

is there an easy way to patch this issue and define findOne method?

Thanks


Reply to this email directly or view it on GitHub:
#38

@1602
Copy link
Owner

1602 commented Mar 1, 2012

Maybe this is undocumented mongoose feature, but for my test it works as expected when I specify sort direction:

User.all({order: 'email DESC'}, console.log);

Let me know if you have any problems with mongoose adapter. I've only fixed redis adapter to hook this feature, all others working just fine.

@TinNT
Copy link
Author

TinNT commented Mar 2, 2012

Thanks for your reply, I tried to install latest release of mongoose and jugglingdb, but it didn't help, the issue is still there, here is the details


➜  node_modules  npm install mongoose
mongoose@2.5.9 ./mongoose 
├── hooks@0.1.9
└── mongodb@0.9.7-3-5
➜  node_modules  npm install jugglingdb
jugglingdb@0.1.1 ./jugglingdb 
└── hashish@0.0.4


------------

User.all({order: 'email DESC'}, function(err, users){
   users.forEach(function(user){
     console.log(user.email);
   })
});

john@hcompany.com
tom@hcompany.com
admin@hcompany.com
tin@hcompany.com
mike@hcompany.com
susan@hcompany.com
test@hcompany.com

note: order by email DESC did not work
---------------

User.all({order: 'email'}, function(err, users){
   users.forEach(function(user){
     console.log(user.email);
   })
});

admin@hcompany.com
john@hcompany.com
mike@hcompany.com
susan@hcompany.com
test@hcompany.com
tin@hcompany.com
tom@hcompany.com



Thanks again.

@1602
Copy link
Owner

1602 commented Mar 6, 2012

Both features implemented now: findOne, DESC, ASC sortings for mongoose

@TinNT
Copy link
Author

TinNT commented Mar 6, 2012

Awesome!!!

Thank you.

@giano
Copy link

giano commented May 18, 2012

thanks!

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

No branches or pull requests

4 participants