sathishkumar
sathishkumar

Reputation: 1816

How to insert multiple records in loopback

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 ?

Upvotes: 2

Views: 4435

Answers (2)

Sagar Jethi
Sagar Jethi

Reputation: 2711

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

Hope this helps.

Upvotes: 4

itssajan
itssajan

Reputation: 830

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.

Upvotes: 4

Related Questions