Giter Club home page Giter Club logo

Comments (13)

wclr avatar wclr commented on September 27, 2024

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.

sibelius avatar sibelius commented on September 27, 2024

in the ChildSchema you just need ChildSchema.fill('another', ...)

it is working, thanks for this awesome plugin

from mongoose-fill.

sibelius avatar sibelius commented on September 27, 2024

Maybe this plugin should provide this out of the box, as a feature

from mongoose-fill.

wclr avatar wclr commented on September 27, 2024

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.

sibelius avatar sibelius commented on September 27, 2024

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.

wclr avatar wclr commented on September 27, 2024

So does it work for you? What extra steps exept defining PostSchema.fill('comments, ..)` needed ?

from mongoose-fill.

sibelius avatar sibelius commented on September 27, 2024

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.

wclr avatar wclr commented on September 27, 2024

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.

wclr avatar wclr commented on September 27, 2024

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.

sibelius avatar sibelius commented on September 27, 2024

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.

sibelius avatar sibelius commented on September 27, 2024

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.

wclr avatar wclr commented on September 27, 2024

actually I believe fill already does what you need
see last example in readme

from mongoose-fill.

sibelius avatar sibelius commented on September 27, 2024

that's awesome, your plugin should be part of the mongoose core

from mongoose-fill.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.