How to insert multiple records in loopback

試著忘記壹切 提交于 2019-12-11 08:31:11

问题


I have collection of records for a model. But there is no method available to insert into Mongo db in Fireloop.

Is there any method available ?


回答1:


Yes there is, in you models create endpoint give an array instead of object

Example: in Products model

this.productApi.create(
  [
    {name: "Toy Car"},
    {name: "Purse"},
    {name: "Charger"}
  ]
).subscribe((res)=>console.log(res))

Hope this helps.




回答2:


Yes, PersistedModel.create([data], callback) As Arguments Optional data argument. Can be either a single model instance or an array of instances. Pass object Pass Array

Hope this helps.



来源:https://stackoverflow.com/questions/45860853/how-to-insert-multiple-records-in-loopback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!