Created
March 7, 2018 19:48
-
-
Save moiz-frost/3b3fe4f12d1feaa5517b4812f2fe4aa1 to your computer and use it in GitHub Desktop.
exchange_seeder.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose') | |
var Schema = mongoose.Schema | |
mongoose.Promise = global.Promise | |
mongoose.connect(process.env.MONGO_URL || 'mongodb://localhost:27017/woxcut') | |
var db = mongoose.connection | |
db.on('error', console.error.bind(console, 'Connection Error:')) | |
db.on('open', function() { | |
for (ex of exchanges) { | |
// Maintain loop state | |
(function(ex) { | |
new Exchange({ name: ex }).save() | |
.then(function() { | |
console.log(ex) | |
if(exchanges[exchanges.length - 1] == ex) { | |
mongoose.connection.close() | |
} | |
}) | |
.catch(function(err) { | |
console.log(err) | |
}) | |
})(ex) | |
} | |
}); | |
// Add exchanges here | |
var exchanges = ['Binanace', 'Bitstamp', 'Kraken', 'Bitfinex', 'Bittrex'] | |
var exchangeSchema = new Schema({ | |
name: String | |
}) | |
var Exchange = mongoose.model('exchange', exchangeSchema) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified it and added to repo
Thanks