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
support for es6 Set? #4627
Comments
It would be pretty tricky because there isn't a good way to tell mongoose what type the set members should have with our current typing system. Would love to support this but don't really see what this would look like in mongoose |
what about something like: function find() {
if (Set && ($in instanceof Set)) {
$in = [...$in]
}
// do the current logic
// ... would this work? this is basically the same logic that would happen outside of mongoose without having to replicate the boilerplate everywhere |
That's fair, we can support sets for cases like that, but I'm hesitant because we don't support sets in any other way, so it would be more difficult to convey "mongoose supports sets in this one limited case" than "mongoose does not support sets at all" |
Totally understandable, and inline with how I envisioned it working as well. The idea is anywhere in mongoose where an array of items is presented a set could optionally take it's place. I realize this is several metric tons of work and I don't expect to see anything anytime soon. Just wanted to put this out there as something that would be super elegant if/when mongoose decides to support some newer es collection types moving foward in the future. |
@mreinstein you can actually write it this way: const cursor = BidPackageModel.find({
projectId: {
$in: Array.from(projectIds),
}
}).cursor() |
I have many mongoose queries models that end up referencing an array of unique ids. An example:
where
projectids
is a set of unique ids I've built up with some little glue logic. Javascript now has aSet
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Setrather than having to cast a Set into a
projectids
Array , it would be awesome if mongoose was capable of supporting sets directly.Is this something that would be realistic/feasible in terms of new features?
The text was updated successfully, but these errors were encountered: