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

Is there a way to define a sub document of sub documents? #5919

Closed
lopugit opened this issue Dec 18, 2017 · 11 comments
Closed

Is there a way to define a sub document of sub documents? #5919

lopugit opened this issue Dec 18, 2017 · 11 comments
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity

Comments

@lopugit
Copy link

lopugit commented Dec 18, 2017

Do you want to request a feature or report a bug?
request a feature, ask about one
What is the current behavior?
Currently you can only define a type of [ObjectId's, ref: 'some model'] but I have really been needing the usefulness of being able to say that a property is an object, where every property of that object must be a sub document or adhere to a schema.

Right now I'm giving my sub document schema a property called title, and a property called value, and then in production creating a "mapped" property on the array, looping over all the sub documents in the array, and going array.mapped[subdocument.title] = subdocument

so I was just wondering if this feature has been thought about?

Please mention your node.js, mongoose and MongoDB version.
node v8 and mongoose v4+ mongodb v idk what it's up to..

ty ty

@vkarpov15
Copy link
Collaborator

Perhaps subdocs? I don't quite understand your question because prose descriptions of code tend to not convey intent well, can you provide some pseudocode please?

@vkarpov15 vkarpov15 added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Dec 27, 2017
@lopugit
Copy link
Author

lopugit commented Dec 29, 2017

yes @vkarpov15 sorry and thanks for the response, not sure why I didn't include some better examples

basically you can define a schema that says

var schema = new Schema({
    list: { type: [{ type: Schema.ObjectId, ref: 'subDoc' }] }
})

Which will limit all values of the list property to Object Id's, but, there's no way to say

var schema = new Schema({
    object: { type: {{ type: Schema.ObjectId, ref: 'subDoc' }} }
})

Which will limit all keyed values of the object property to ObjectId's

I hope this helps

@vkarpov15
Copy link
Collaborator

I see what you're asking for, arbitrary keys in an object is not something we support, but we're planning on adding that in Q1 2018. Follow #681 for updates.

@lopugit
Copy link
Author

lopugit commented Dec 30, 2017

@vkarpov15 would it be that hard? It seems like just changing the array validation mechanism to loop over own properties instead of 0-length-1 like in an array, I might work on an implementation because I've needed it for some time.

thanks for your reply :) <3

@vkarpov15
Copy link
Collaborator

Yeah I think a custom map type would be pretty useful. You're welcome to give it a shot, you can try building a custom schema type plugin. You can ask for help on our slack channel

@lopugit
Copy link
Author

lopugit commented Jan 1, 2018

@vkarpov15
what's up with this link? http://plugins.mongoosejs.io/

It doesn't load for me

@vkarpov15
Copy link
Collaborator

It's been down for a bit, haven't gotten around to fixing it because the app as written has some heavy memory needs.

@lopugit
Copy link
Author

lopugit commented Jan 1, 2018

@vkarpov15 it's written in node right? I've run into some memory issues with node apps too, you just kind of write whatever logic you want, and then apps can balloon when running in production...

I can try to write the plugin off other plugin examples :)

@vkarpov15
Copy link
Collaborator

Hahah the reason for ballooning is it imports every npm module that has "mongoose" in the keywords into a mongodb instance. We managed to get it to work with JSONstream but its still not as robust as I'd like.

@lopugit
Copy link
Author

lopugit commented Jan 13, 2018

wait what how do you store a file system in mongodb?

@vkarpov15
Copy link
Collaborator

Not a file system, just a doc for every npm module with mongoose in the keywords. Nothing that sophisticated.

If you want a mongodb backed file system theres mongofuse https://github.com/scotthernandez/mongo-fuse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
Projects
None yet
Development

No branches or pull requests

2 participants