-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Query and construct document with aliases with Model.translateAliases #5338
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
Conversation
Maybe I should put it under Schema instead of Model? |
'年齢': 30 | ||
}), | ||
// How translated aliases suppose to look like | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure separating out dotted paths is the right behavior here. If you're querying by '年齢', you'd want to query 'bio.age': 30
rather than bio: { age: 30 }
, because the latter will only match if bio
is an object that contains exactly 1 key, age
. On the other hand, 'bio.age': 30
would match even if bio
has other keys, for example birthday
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I was over thinking it
Do you prefer that I put it under schema instead of model?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I think schema
is actually the better place to put the logic, but there should still be a helper function on model. But this code looks good, I'm gonna merge it into the 4.11 branch
Any plans to have querying with aliases without additional query code? Person.findOne({ name: 'Ben' }, ...) where var personSchema = new Schema({
n: {
type: String,
alias: 'name'
}
}); Would be a great way to change schema without breaking existing query code |
Pre-hooks seems like a good way to implement transparent aliased queries. I'll look on to it next weekend |
Should be easy to implement as a plugin, but haven't tried. I appreciate the suggestion, but please open up a new issue instead of commenting on a closed one 👍 |
Follow up from #5321
Usage: