This repository has been archived by the owner on Mar 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (60 loc) · 2.85 KB
/
index.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
const mongoose = require('mongoose');
const Atm = require('./src/atm-model');
const Ats = require('./src/ats-model');
const Ats3 = require('./src/ats3-model');
const Ats4 = require('./src/ats4-model');
(async () => {
try {
await mongoose.connect('mongodb://localhost:27017/discrm-bug-db', {
// enable automatic index creation
autoIndex: true,
});
mongoose.set('debug', true);
await createFixtures();
console.log('Result for "find" on collection WITHOUT inheritance does not loose filters:');
const findSimpleResult = await Atm.find({ serialNumber: 'atm-2' });
console.log(findSimpleResult);
console.log('-----------------------------------');
console.log('Result for "find one" on collection WITH inheritance does loose filters:');
// first item in database is returned since filters are list when mongoose executes the query (see debug output)
const findOneResult = await Ats.findOne({ serialNumber: 'ats-3-3' });
console.log(findOneResult);
console.log('-----------------------------------');
console.log('Result for "find" on collection WITH inheritance does loose filters:');
// all items in database are returned since filters are list when mongoose executes the query (see debug output)
const findManyResult = await Ats.find({ serialNumber: 'ats-3-1' });
console.log(findManyResult);
} catch (e) {
throw new Error(e);
}
})();
async function createFixtures() {
// clear db
await Atm.collection.drop();
await Ats.collection.drop();
// Atm (does not use inheritance)
const aAtm = new Atm({deviceId: '1', serialNumber: 'atm-1', partNumber: 'atm-111'});
const bAtm = new Atm({deviceId: '2', serialNumber: 'atm-2', partNumber: 'atm-222'});
const cAtm = new Atm({deviceId: '3', serialNumber: 'atm-3', partNumber: 'atm-333'});
// Ats3 ( inherits from base model using discriminator functionality)
const aAts3 = new Ats3({deviceId: '1', serialNumber: 'ats-3-1', partNumber: 'ats3-111'});
const bAts3 = new Ats3({deviceId: '2', serialNumber: 'ats-3-2', partNumber: 'ats3-222'});
const cAts3 = new Ats3({deviceId: '3', serialNumber: 'ats-3-3', partNumber: 'ats3-333'});
// Ats4 ( inherits from base model using discriminator functionality)
const aAts4 = new Ats4({deviceId: '1', serialNumber: 'ats-4-1', partNumber: 'ats4-111'});
const bAts4 = new Ats4({deviceId: '2', serialNumber: 'ats-4-2', partNumber: 'ats4-222'});
const cAts4 = new Ats4({deviceId: '3', serialNumber: 'ats-4-3', partNumber: 'ats4-333'});
// persist to db
// Atm
await aAtm.save();
await bAtm.save();
await cAtm.save();
// Ats3
await aAts3.save();
await bAts3.save();
await cAts3.save();
// Ats4
await aAts4.save();
await bAts4.save();
await cAts4.save();
}