-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Comments
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? |
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 var schema = new Schema({
object: { type: {{ type: Schema.ObjectId, ref: 'subDoc' }} }
}) Which will limit all keyed values of the I hope this helps |
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. |
@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 |
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 |
@vkarpov15 It doesn't load for me |
It's been down for a bit, haven't gotten around to fixing it because the app as written has some heavy memory needs. |
@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 :) |
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. |
wait what how do you store a file system in mongodb? |
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 |
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
The text was updated successfully, but these errors were encountered: