Comments (6)
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.
Hi @JohannesMerz,
did you manage to achieve your goal?
from mongoose-data-seed.
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.
@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.
Ahh, nice! Thanks for the quick response. That clears everything up.
from mongoose-data-seed.
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)
- Error: Cannot find module 'core-js/stable'
- Problem running inside docker-compose using volumes HOT 2
- An in-range update of mongoose is breaking the build 🚨 HOT 2
- Incorrect installing v 2.1.0 HOT 3
- An in-range update of mongoose is breaking the build 🚨
- An in-range update of eslint is breaking the build 🚨 HOT 3
- Cannot use ES6 imports in md-seed run command HOT 6
- Run command returns TypeError: Seeder is not a constructor HOT 5
- An in-range update of babel7 is breaking the build 🚨 HOT 1
- An in-range update of babel7 is breaking the build 🚨 HOT 6
- An in-range update of eslint is breaking the build 🚨 HOT 3
- Docs HOT 1
- An in-range update of babel7 is breaking the build 🚨 HOT 13
- An in-range update of prettier is breaking the build 🚨 HOT 2
- An in-range update of core-js is breaking the build 🚨 HOT 4
- Custom md-seed-config.js location HOT 4
- md-seed run command display an error.
- An in-range update of babel7 is breaking the build 🚨
- Support for Typescript seeders or allow passing custom extension HOT 1
- Not able to run seeders 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 mongoose-data-seed.