var data = [{
'cat_name':'fashion'
},
{
'cat_name':'food'
}
];
orm.models.category.bulkCreate(data,{individualHooks: true})
.then(function(response){
res.json(response);
})
.catch(function(error){
res.json(error);
});
bulkCreate([...], { updateOnDuplicate: ["name"] })
db.connections.update({
user: data.username,
chatroomID: data.chatroomID
}, {
where: { socketID: socket.id },
returning: true,
plain: true
})
.then(function (result) {
console.log(result);
// result = [x] or [x, y]
// [x] if you're not using Postgres
// [x, y] if you are using Postgres
});
async function updateOrCreate (model, where, newItem) {
// First try to find the record
const foundItem = await model.findOne({where});
if (!foundItem) {
// Item not found, create a new one
const item = await model.create(newItem)
return {item, created: true};
}
// Found an item, update it
const item = await model.update(newItem, {where});
return {item, created: false};
}
Project.update(
{ title: 'a very different title now' },
{ where: { _id: 1 } }
)
Your_model.update({ field1 : 'foo' },{ where : { id : 1 }});
Your_model.update({ field1 : 'bar' },{ where : { id : 4 }});
await Project.update(
{ title: 'a very different title now' },
{ where: { _id: 1 } }
);