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

support for es6 Set? #4627

Open
mreinstein opened this issue Oct 14, 2016 · 5 comments
Open

support for es6 Set? #4627

mreinstein opened this issue Oct 14, 2016 · 5 comments
Labels
discussion If you have any thoughts or comments on this issue, please share them!

Comments

@mreinstein
Copy link

mreinstein commented Oct 14, 2016

I have many mongoose queries models that end up referencing an array of unique ids. An example:

const cursor = BidPackageModel.find({
    projectId: {
        $in: projectIds,
    }
}).cursor()

where projectids is a set of unique ids I've built up with some little glue logic. Javascript now has a Set https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set

rather 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?

@vkarpov15
Copy link
Collaborator

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

@vkarpov15 vkarpov15 added the discussion If you have any thoughts or comments on this issue, please share them! label Oct 21, 2016
@mreinstein
Copy link
Author

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

@vkarpov15
Copy link
Collaborator

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"

@mreinstein
Copy link
Author

mreinstein commented Oct 22, 2016

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.

@stalniy
Copy link

stalniy commented Feb 23, 2017

@mreinstein you can actually write it this way:

const cursor = BidPackageModel.find({
    projectId: {
        $in: Array.from(projectIds),
    }
}).cursor()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion If you have any thoughts or comments on this issue, please share them!
Projects
None yet
Development

No branches or pull requests

3 participants