testBatchInsertDocs.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Created by Tony on 2017/4/24.
  3. */
  4. var test = require('tape');
  5. var mongoose = require('mongoose');
  6. var dbm = require("../../../config/db/db_manager");
  7. var testdb = dbm.getLocalConnection("Demo");
  8. var Schema = mongoose.Schema;
  9. //testBatchInsert
  10. var BatchInsertSchema = new Schema({
  11. "ID": Number,
  12. "dispName" : String
  13. });
  14. var testModel = testdb.model("testBatchInsert", BatchInsertSchema, "testBatchInsert");
  15. test('test batch insert docs', function(t){
  16. var arr = [];
  17. arr.push(new testModel({ID: 1, dispName: "name1"}));
  18. arr.push(new testModel({ID: 2, dispName: "name2"}));
  19. arr.push(new testModel({ID: 3, dispName: "name3"}));
  20. testModel.collection.insert(arr, null, function(err, docs){
  21. if (err) {
  22. t.pass('pass with error');
  23. } else {
  24. t.pass('pass with: ' + docs.insertedCount + ' records were inserted!');
  25. }
  26. t.end();
  27. })
  28. });
  29. test('finish', function (t) {
  30. mongoose.disconnect();
  31. t.pass('closing db connection');
  32. t.end();
  33. });