Giter Site home page Giter Site logo

Comments (6)

sharvit avatar sharvit commented on June 26, 2024

Hi @JohannesMerz, thank you for opening this issue.

You should be able to do something very similar to what you did.

The run method is returning an observable (not a promise), you can look here to see usage example:
https://github.com/sharvit/mongoose-data-seed/blob/master/src/bin/run/index.js#L71

Notice, i am working on a refactoring, i will continue to use observable but the inner next implementation will be different after releasing the next version.

from mongoose-data-seed.

sharvit avatar sharvit commented on June 26, 2024

Hi @JohannesMerz,
did you manage to achieve your goal?

from mongoose-data-seed.

JohannesMerz avatar JohannesMerz commented on June 26, 2024

oh i guess this can be closed. I didn't quite get what you suggested above.

A section in the readme of what can be done programmatically and not through the cli would be really helpful.

from mongoose-data-seed.

sharvit avatar sharvit commented on June 26, 2024

@JohannesMerz I shared with you the code that uses the seed method internally, I thought it can help.

You can write something like:

import { seed } from 'mongoose-data-seed';

seed().subscribe({
  next: ({ name, results }) => console.log(name, results),
  error: ({ name, error }) => console.log(name, error),
  complete: () => console.log('Completed!'),
});

You can also pass selectedSeeders array to the seed method:

const selectedSeeders = ['Users', 'Posts'];

seed(selectedSeeders).subscribe({ ... });

Let me know if I can do more to help!
I am more than happy to do so 😄

I will update the docs soon.

from mongoose-data-seed.

JohannesMerz avatar JohannesMerz commented on June 26, 2024

Ahh, nice! Thanks for the quick response. That clears everything up.

from mongoose-data-seed.

zhonghuiwen avatar zhonghuiwen commented on June 26, 2024

Hi @JohannesMerz i tried running seed() in in my express app but i'm getting this error:

TypeError: Class extends value undefined is not a constructor or null

I've googed it and it seems to be some sort of cyclic reference according to this: https://stackoverflow.com/questions/37312197/node-js-v6-2-0-class-extends-is-not-a-function-error/37312355#37312355

But i'm not sure how the cyclic reference is occurring, would you know how this is happening?

class ResourceActionSeeder extends Seeder {
app_1    |                                    ^
app_1    |
app_1    | TypeError: Class extends value undefined is not a constructor or null
app_1    |     at Object.<anonymous> (/usr/src/app/seeders/resource-actions.seeder.js:9:36)
app_1    |     at Module._compile (module.js:649:30)
app_1    |     at Object.Module._extensions..js (module.js:660:10)
app_1    |     at Module.load (module.js:561:32)
app_1    |     at tryModuleLoad (module.js:501:12)
app_1    |     at Function.Module._load (module.js:493:3)
app_1    |     at Module.require (module.js:593:17)
app_1    |     at require (internal/module.js:11:18)
app_1    |     at Object.<anonymous> (/usr/src/app/md-seed-config.js:1:87)
app_1    |     at Module._compile (module.js:649:30)
app_1    |     at Object.Module._extensions..js (module.js:660:10)
app_1    |     at Module.load (module.js:561:32)
app_1    |     at tryModuleLoad (module.js:501:12)
app_1    |     at Function.Module._load (module.js:493:3)
app_1    |     at Module.require (module.js:593:17)
app_1    |     at require (internal/module.js:11:18)

This is the code from where i want to programatically seed the db

const { seed } = require('mongoose-data-seed');
...
app.get('/seeddb', (req, res, next) => {
  if (process.env.NODE_ENV === 'development') {
    seed().subscribe({
      next: ({ name, results }) => {
        log.debug(`name: ${name}`);
        log.debug(`results: ${results}`);
        res.end();
        next();
      },
      error: ({ name, error }) => {
        log.debug(`name: ${name}`);
        log.debug(`error: ${error}`);
        res.end();
        next();
      },
      complete: () => next(),
    });
  } else {
    res.status(400).send('Permission Denied');
  }
});

from mongoose-data-seed.

Related Issues (20)

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.