3

I want to do bulk insert with array of json objects. I believe there is support for bulk insert with mongoose. How to do the bulk insert with typegoose?

Here is my current model's options:

const JobModel = new Job().getModelForClass(Job, {
  schemaOptions: {
    id: false,
    versionKey: false,
    timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' },
  },
});
hasezoey
  • 998
  • 9
  • 24
Ashwin
  • 43
  • 3
  • Does this answer your question? [Mongoose (mongodb) batch insert?](https://stackoverflow.com/questions/16726330/mongoose-mongodb-batch-insert) – finder2 Jan 22 '20 at 08:21
  • We already had an [similar issue](https://github.com/typegoose/typegoose/issues/197) on the typegoose repository, mabye it helps – hasezoey Mar 03 '20 at 16:22

1 Answers1

2

Model.bulkSave()

Create multiple documents and then save all of them at once.

const job1 = new JobModel()
job1.title = 'Title1'

const job2 = new JobModel()
job2.title = 'Title2'

const job3 = new JobModel()
job3.title = 'Title3'

await JobModel.bulkSave([job1, job2, job3])
Jawad Ahbab
  • 1,462
  • 1
  • 19
  • 31