-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
distinct return ts type is unclear #11306
Comments
returns as type import * as mongoose from 'mongoose';
interface IModelEntry {
field: string
}
const schema = new mongoose.Schema<IModelEntry>({
field: String
})
const model: mongoose.Model<IModelEntry> = mongoose.model<IModelEntry>("collection", schema);
async function test() {
const response = await model.distinct('field', {});
}
test(); |
Confirmed that the return type of We'll add the ability to do |
@vkarpov15 I was thinking the correct type of
This should behave more like mongodb does, i.e., if you give something that isn't a key on the document, you still get an empty array or something If you're okay with this type, I'd be happy to raise a PR with tests. |
@kaulshashank looks good as long as tests pass. Feel free to put in a PR, we'll review it. My only potential concern is that this change will be backwards breaking; but if it is, we can always merge into the 8.0 branch. |
Do you want to request a feature or report a bug?
Bug(?)
What is the current behavior?
distinct returns an array of Query doc type
According to the docs: distinct returns the distinct values of the given field that match filter. So if field is a string, a string[] should return.
However response is of type IModelEntry[]
What is the expected behavior?
distinct returns array of string
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
16.11, 5.13.14, 5.0.4
The text was updated successfully, but these errors were encountered: