简体   繁体   中英

how to perform sequelize bulk insert in nodejs

I'm writing rest using nodejs,sequelize and MySQL. I want to insert 6000 record in MySQL table using a bulk insert of sequelize so bulk insert is possible or not?

// temp is my array 
SymbolsData.bulkCreate(temp)
        .then((dbRes) => {
            console.log(dbRes);
        })
        .catch((err) => {
            console.log('error', err);
        });

in my temp array, there are many objects without object key so I added object key based on the database field name and then pass that array to bulkInsert and it's working good. I missed the object key.

let temp = [];
//push key pair value in array here db_col_name is column name of database & value is which we want to pass
temp.push({db_col_name:value});
// now, pass array of objects in bulkcreate
SymbolsData.bulkCreate(temp)
        .then((dbRes) => {
            console.log(dbRes);
        })
        .catch((err) => {
            console.log('error', err);
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM