-
Notifications
You must be signed in to change notification settings - Fork 376
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
findOne convenience function #148
Comments
There is a |
Haha, yes, having more than one result would be indicative of an issue. More along the lines of what I hoped to solve with this idea is eliminating the User.find({ username: username }, function (err, users) {
var user = users[0];
... with // findOne or one, syntax is obviously up to you.
// I'm familiar with the findOne vs. find from the Mongoose API.
User.[findOne | one]({ username: username }, function (err, user) {
// no need to access the first element.
... Will the alias Model.one() cover this concept? From my understanding (which may very well be incorrect), even if it is a limit of 1 it will still return an array, albeit with a length of 1. |
Could also call it 'first()'. |
Yes, the simple implementation I added will return an |
For now it forces a callback, you can't do this: Model.one(....).run(function (...) {
}); For now, only: Model.one(...., function (...) {
}); |
If you can fit a quick nice feature into your next release, I would like a
findOne
function in addition to thefind(...).limit(1)
functionality. This would make integration with user validation/authentication a little cleaner IMO.Thank you, I'm very appreciative of this library. There are not very many good ORM libraries for MySQL.
The text was updated successfully, but these errors were encountered: