forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDeepNestedDocArray.js
More file actions
37 lines (28 loc) · 923 Bytes
/
createDeepNestedDocArray.js
File metadata and controls
37 lines (28 loc) · 923 Bytes
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
'use strict';
const mongoose = require('../');
run().catch(err => {
console.error(err);
process.exit(-1);
});
async function run() {
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_benchmark');
const levels = 12;
let schema = new mongoose.Schema({ test: { type: String, required: true } });
let doc = { test: 'gh-14897' };
for (let i = 0; i < levels; ++i) {
schema = new mongoose.Schema({ level: Number, subdocs: [schema] });
doc = { level: (levels - i), subdocs: [{ ...doc }, { ...doc }] };
}
const Test = mongoose.model('Test', schema);
if (!process.env.MONGOOSE_BENCHMARK_SKIP_SETUP) {
await Test.deleteMany({});
}
const insertStart = Date.now();
await Test.create(doc);
const insertEnd = Date.now();
const results = {
'create() time ms': +(insertEnd - insertStart).toFixed(2)
};
console.log(JSON.stringify(results, null, ' '));
process.exit(0);
}