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
Hydrating browser-side Documents with populated SubDocuments using isomorphic schemas #3788
Comments
I think right now the only workaround would be to explicitly get Great choice on riot btw, I've been using it a bit myself. How are you liking it so far? |
Yeah, I was afraid of that, I should stop trying to get it to work this way :) I stumbled upon Riot when I was looking for an isomorphic framework. I'm actually really pleased with it. Decided to start with https://github.com/ListnPlay/riot-isomorphic: ES6 + Babel + Browserify + Feathers + Primus + Passport + Gulp + Livereload goodness from the get-go :D Then started modifying it to my needs. Feathers-mongoose-advanced plays reasonably well with feathers-client over Primus, but if you are going to do complex interlinked schemas and more than CRUD, then you hit its limits pretty fast. I'm sticking with mongoose for sure, though. Kudos! |
@jubr I stumbled on the same problem, I can't populate documents' paths on the client-side (browser), were you able to find a solution? I'm not even able to manually populate the paths, saying |
@lucafaggianelli can you please open a new issue and follow the issue template? |
I did #8605 |
In reaction to #3774, here's what I am trying to do. Currently I'm using a combination of riot.js, feathers.js and Primus to transport data from Node/Mongoose to the browser and back. But the case I am describing is generic. Client-side I am trying to fully instantiate/hydrate documents so I can use validation, embedded document and subdocument modifications, using isomorphic techniques as much as possible.
This is only a part of the data structure and simplified.
Category
andThingTemplate
are used in a couple of other places, so I think I need db-refs for these. Please note that I am pretty new to Mongoose & I wonder if I'm sticking enough to the 'No' in NoSQL with my approach. Creation, modification and validation of these isomorphic schemas is performed at both the client-side and the server-side.Moving on to the server-side query. The actual query is initiated client-side, but results in something like this on the server, the only non-isomorphic part of the code:
The data transmitted might look something like this:
On the client-side this is then received, instantiated and used in various ways:
Saving of the modified document is left out of scope for brevity. Brief - a foreign concept, indeed 😀
Save to say (pun intended) that the modification semantics are meant to be used for efficient saving at a later time.
For instantiation with subdocuments from populated data I've managed to modify
Document
'sfunction init()
to check forschema.options.ref
and pass in the actual subdocschema
to cast to explicitly usingself.set()
.Then, for later modification with
.push()
or.set()
I was able to fillval.constructor.modelName
(from Model-land) by explicitly setting it ondoc.constructor
after construction in a custom wrapper aroundmongoose.document(obj, xSchema)
for each schema.I suspect that @robschley's proposed BrowserModel in #3774 will take care of most of these challenges. Plus the possibility of plugins to elegantly handle the actual queries/saving.
Yes, I am aware of the hackiness, just wanted to see if I could, it is semi-working at the moment. Still seeing a lot of
$__
andschema
properties in thetoObject()
result, probably due to my coercion of various objects. Is there a better way to do this currently?The text was updated successfully, but these errors were encountered: