12345678910111213141516171819202122232425262728293031323334353637 |
- /**
- * Created by Tony on 2017/4/24.
- */
- var test = require('tape');
- var mongoose = require('mongoose');
- var dbm = require("../../../config/db/db_manager");
- var testdb = dbm.getLocalConnection("Demo");
- var Schema = mongoose.Schema;
- //testBatchInsert
- var BatchInsertSchema = new Schema({
- "ID": Number,
- "dispName" : String
- });
- var testModel = testdb.model("testBatchInsert", BatchInsertSchema, "testBatchInsert");
- test('test batch insert docs', function(t){
- var arr = [];
- arr.push(new testModel({ID: 1, dispName: "name1"}));
- arr.push(new testModel({ID: 2, dispName: "name2"}));
- arr.push(new testModel({ID: 3, dispName: "name3"}));
- testModel.collection.insert(arr, null, function(err, docs){
- if (err) {
- t.pass('pass with error');
- } else {
- t.pass('pass with: ' + docs.insertedCount + ' records were inserted!');
- }
- t.end();
- })
- });
- test('finish', function (t) {
- mongoose.disconnect();
- t.pass('closing db connection');
- t.end();
- });
|