deno.land / x / mongoose@6.7.5 / benchmarks / benchjs / delete.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';const mongoose = require('../../lib');const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();
const Schema = mongoose.Schema;const mongoClient = require('mongodb').MongoClient;
// to make things work in the way the are normally described online.../* *global.Schema = Schema; *global.mongoose = mongoose; */
/** * These are all the benchmark tests for deleting data */
mongoose.connect('mongodb://localhost/mongoose-bench', function (err) { if (err) { throw err; } mongoClient.connect('mongodb://localhost', function (err, client) { if (err) { throw err; }
const db = client.db('mongoose-bench');
const UserSchema = new Schema({ name: String, age: Number, likes: [String], address: String, });
const User = mongoose.model('User', UserSchema); const user = db.collection('user');
const mIds = []; const dIds = [];
const data = { name: 'name', age: 0, likes: ['dogs', 'cats', 'pizza'], address: ' Nowhere-ville USA', };
// insert all of the data here let count = 1000; for (let i = 0; i < 500; i++) { User.create(data, function (err, u) { if (err) { throw err; } mIds.push(u.id); --count || next(); }); const nData = {}; nData.name = data.name; nData.age = data.age; nData.likes = data.likes; nData.address = data.address; user.insertOne(nData, function (err, res) { dIds.push(res.insertedId); --count || next(); }); }
function closeDB() { User.count(function (err, res) { if (res !== 0) { console.log('Still mongoose entries left...'); } mongoose.disconnect(); }); user.count({}, function (err, res) { if (res !== 0) { console.log('Still driver entries left...'); } if (err) { throw err; } client.close(); }); }
suite .add('Delete - Mongoose', { defer: true, fn: function (deferred) { User.remove({ _id: mIds.pop() }, function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Delete - Driver', { defer: true, fn: function (deferred) { user.deleteOne({ _id: dIds.pop() }, function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .on('cycle', function (evt) { if (process.env.MONGOOSE_DEV || process.env.PULL_REQUEST) { console.log(String(evt.target)); } }) .on('complete', function () { closeDB(); if (!process.env.MONGOOSE_DEV && !process.env.PULL_REQUEST) { const outObj = {}; this.forEach(function (item) { const out = {}; out.stats = item.stats; delete out.stats.sample; out.ops = item.hz; outObj[item.name.replace(/\s/g, '')] = out; }); console.dir(outObj, { depth: null, colors: true }); } }); function next() { suite.run({ async: true }); } });});
mongoose

Version Info

Tagged at
a year ago