mongoose-cachedBulkInsert
Insert docs into your collection every n documents and/or every n seconds. (n is up to you!)
Usage
test.js
#!/usr/bin/env node'use strict'; const mongoose = ;const Schema connection = mongoose;const cachedBulkInsert = ;const DB = 'test';const URI = `mongodb://localhost:27017/`;const OPTS = useNewUrlParser: true useUnifiedTopology: true ; const schema = name: String; let array = ; const pluginOptions = array wait: 5000 cycles: 3 { if res && resinsertedCount console; }; schema; const Test = mongoose; { await mongoose; await connection; for let i = 0; i < 100; i++ await Test ; for let i = 0; i < 19; i++ await Test; await ; await connection;} ; { return { ; };}
Output
$ ./test.js
lengthBasedInsert: 20
lengthBasedInsert: 20
lengthBasedInsert: 20
lengthBasedInsert: 20
lengthBasedInsert: 20
intervalBasedInsert: 19
$