Comments (13)
mongoose-fill works on the model it self with predefined .fill(..)
config. So it will not fill props of populated objects (either you populate them with deep-populate
or standard populate
out of the box.
But actually something like this I think that this may work for you:
// you define fill on child
ChildSchema.fill('another', function(callback){
...
})
Then you define fill on parent:
ModelSchema.fill('child.another', function(callback){
// this.child should be populated
// probably it will in your case
this.child.fill('another', callback)
})
Not shure if child.another
(with dot) for fill
name will work out, if not replace it with something else.
Actually I think it can be accompblished in some way.
from mongoose-fill.
in the ChildSchema you just need ChildSchema.fill('another', ...)
it is working, thanks for this awesome plugin
from mongoose-fill.
Maybe this plugin should provide this out of the box, as a feature
from mongoose-fill.
Actually I didn't understand you problem completly what works, what should work and what doesn't =)
you have fill
defined on you child, and you want it to be auto filled from querying parent model using .fill('child.another')
?
from mongoose-fill.
My use case is this:
NewsFeed model has one Post that has many Comments
NewsFeed.find().deepPopulate(['post', 'post.user']).fill('post.comments').exec()
Comments are not embedded on Post, neither Post references all its comments, that's why I need to fill comments inside posts
My newsfeed do not have only Posts, it has other models
from mongoose-fill.
So does it work for you? What extra steps exept defining PostSchema.fill('comments
, ..)` needed ?
from mongoose-fill.
I have to define:
NewsFeedSchema.fill('post.comments', (cb) => this.post.fill('comments') )
PostSchema.fill('comments', (cb) => Comment.find({postId: this._id}).exec(cb))
instead of just having the fill in the child schema
from mongoose-fill.
Ah ok, well this probably could be supported out of the box, but not sure because, there is seem to be too much magic already.)
from mongoose-fill.
Besides mongoose-fill
sitll kinda hack to get rid of callback hell with custom methods and simplify the code (though not more than embedded populate
). With async/await
maybe it will be more convinient to use custom methods, but I prefere rxjs streams currently for this purpose.)
from mongoose-fill.
Callback is really a hell.
I'm using koa@2 that uses async/await
, that's awesome.
I wish mongoose interoperability with async function is better
from mongoose-fill.
One think that will make this plugin even better is to accept parameters on fill
For instance
Post.fill('comments', (args, cb) => Comment.find({postId: this._id}).limit(args.limit).exec(cb));
Post.fill('comments', 10).exec(); // get only 10 comments of Post
I'm going to see whether I can implement it and provide a PR for this case
from mongoose-fill.
actually I believe fill
already does what you need
see last example in readme
from mongoose-fill.
that's awesome, your plugin should be part of the mongoose core
from mongoose-fill.
Related Issues (19)
- Fill is not a function - when using with latest mongoose HOT 2
- Document the requirement to set virtuals property on schema HOT 1
- document#fill does not return a promise HOT 4
- Exec works only with Promise HOT 3
- Work with aggregation HOT 2
- Is it possible to return a Promise instead of callback?
- Mongoose hooks HOT 2
- throws and error with mongoose 4.13.7 HOT 1
- Does not work with mongoose-paginate? HOT 1
- Support fill propagation to field models HOT 23
- Does not work with ES6 arrow functions.
- this.id or this._id are undefined
- test HOT 2
- Current version on NPM fails HOT 2
- Any reason why the callback parameter comes last? HOT 2
- Fill property in array of subdocs? HOT 11
- Add a fillAll() to fill all defined fill fields on a model/doc/schema HOT 2
- Cannot read property 'model' of undefined HOT 11
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 mongoose-fill.