Comments (10)
Thanks for opening an issue.
Do you support pre and post hooks? I couldn't find any references to that in the docs. If not, is it anywhere on the roadmap?
Pre and post hooks for what exactly?
from hapi-mongo-models.
Thanks for responding.
What I meant was the equivalent of the middleware in mongoose, or callbacks in Mongoid (where I'm just coming from to Node).
from hapi-mongo-models.
Oh I see. This hasn't come up before. We don't have models in the sense that you'd change instance data and call a save
method, although you could create a save
method in your own models. Also keep in mind that we're not validating against the schema when creating or updating records, that's up to you to use.
My initial thoughts are;
- we don't have any existing life cycle events or extension points today
- since you're already creating a model for each collection, if you want to get in between (pre/post) of a call, you could overwrite some method in your model and proxy the call to mongo directly.
from hapi-mongo-models.
Sorry, I don't quite understand the bit about save
. I do see insert
and update
methods here, but indeed no save
. Does that mean I'll need to call save
on the native mongodb client to actually persist the document? Do you have an example of this that works well with this project?
I'm new to hapi (and indeed Node) but I'm assuming schema validation à la mongoose should be fairly straightforward with Joi in the handler config itself, isn't it? That in fact is reason enough for me to consider this project, because I don't like the idea of introducing another DSL for validation.
Re pre/post, I'm still finding my way here but I think it'd be hard to beat the elegance of the lifecycle methods and it would be great if we could natively support them here.
from hapi-mongo-models.
Sorry, I don't quite understand the bit about
save
.
Meaning when you create a model it doesn't come with a save
method on it's prototype. And when you call insert
or update
on a model class you're passing in the object data you want persisted, it isn't coming from the "instance" of your model.
Does that mean I'll need to call save on the native mongodb client to actually persist the document?
Not exactly. From the docs you linked to:
Save
Shorthand for insert/update is save - if _id value set, the record is updated if it exists or inserted if it does not; if the _id value is not set, then the record is inserted as a new one.
As you can see, the native save
method isn't related to models or documents persisting themselves.
Do you have an example of this that works well with this project?
Take a look at Frame.
Re pre/post, I'm still finding my way here but I think it'd be hard to beat the elegance of the lifecycle methods and it would be great if we could natively support them here.
I need some more convincing. I'd like to see what having these hooks allows us to do that we can't do without them.
from hapi-mongo-models.
Thanks for pointing me to Frame, will take a look at it.
I can't speak for others, but I've used callbacks variously as utilities to keep my code organised. It's useful to track the lifecycle of an object's creation if I don't have control of where or how it's getting created, as long as there are a few checks or additional things I can do to it or to other models that may be affected by its contents. I've also used it to set some fields to nil/null before saving if they're being received as empty strings from the client, etc (effectively, validation). One may argue that some of these things could and sometimes should be done just before/after the object is being directly saved, but callbacks give me the option of keeping things DRY.
Slightly off-topic, how well does HMM deal with nested documents?
from hapi-mongo-models.
I'm not sure what HMM is.
from hapi-mongo-models.
I'm surprised you haven't yet thought of an acronym for your project ;)
I was trying to figure out from the docs and tests if hapi-mongo-models is designed to play well with (deeply) nested documents out of the box, but couldn't find anything. Admittedly, I haven't yet played with it enough to test that out myself.
from hapi-mongo-models.
I'm surprised you haven't yet thought of an acronym for your project ;)
I see now. Haha.
I was trying to figure out from the docs and tests if
hapi-mongo-models
is designed to play well with (deeply) nested documents out of the box, but couldn't find anything.
If there are limitations they shouldn't be from this library. The more accurate question to ask is what limitations does mongodb have with nested documents and the same goes for Joi.
from hapi-mongo-models.
Makes sense, I'll look that up and open another issue if it doesn't work as expected.
from hapi-mongo-models.
Related Issues (20)
- Can't use Mongo Native method Aggregate HOT 3
- Not authorized on dbname to execute command HOT 1
- QUESTION: Does this plug-in support associations? HOT 2
- Issue with updateOne & update Many HOT 4
- server.start() to include Mongo models? HOT 3
- v6.0.0 release notes
- Add a modelsDirectory plugin option
- using aggregate function HOT 2
- Not expected results in v6.0.0 responses HOT 3
- Multiple db support HOT 1
- MongoDB custom logger HOT 1
- Unable to get the instantiated db reference. HOT 1
- Hapi v17 support HOT 1
- Migrate callbacks pattern to async/await (hapi v17)
- Support for ssh tunnel ? HOT 6
- models "path/to/customer" might be off? HOT 2
- Migration help HOT 1
- Plugin example for 7.x.x? HOT 3
- $elemMatch returns all subjects HOT 1
- If connection.db is optional, why is there an assertion error if it isn't provided? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hapi-mongo-models.