node.js - Sequelize bulkCreate from JSON File -


i create json file records insert , use model.bulkcreate insert records @ once when read file "typeerror: records.map not function"

database.js

fs.readfile(__dirname + "/databasetables/consoleandplatform.json", function(err, data){     consoleandplatform.bulkcreate(data.tostring())   }) 

consoleandplatform.json

[{console: "xbox", platform: "xbox 360", name: "xbox 360"},{ console: "xbox", platform: "xbox one", name: "xbox one"},{ console: "xbox", platform: "xbox live", name: "xbox live"},{ console: "ps", platform: "ps4", name: "playstation 4"}] 

thanks help

ok found solution maybe helpful someone. first of json wrong, should be:

[ {     "console": "xbox",     "platform": "xbox 360",     "name": "xbox 360" }, {     "console": "xbox",     "platform": "xbox one",     "name": "xbox one" }, {     "console": "xbox",     "platform": "xbox live",     "name": "xbox live" }] 

and second need json.parse string result:

consoleandplatform.bulkcreate(json.parse(data.tostring())) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -