-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.ts
66 lines (57 loc) · 1.77 KB
/
test.ts
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
// NodeJS: 18.10.0
// MongoDB: 5.0 (Docker)
// Typescript 4.9.5
// import { getModelForClass, modelOptions, prop } from '@typegoose/typegoose'; // @typegoose/typegoose@11.0.2
import { assertion } from '@typegoose/typegoose/lib/internal/utils';
import * as mongoose from 'mongoose'; // mongoose@7.0.5
import { inspect } from 'util';
// @modelOptions({})
// class TestingMultiDimArrays {
// @prop({ type: Number, items: Number, dim: 2 })
// public intArray?: number[][];
// }
// const TestingMultiDimArraysModel = getModelForClass(TestingMultiDimArrays);
const schema = new mongoose.Schema({
intArray: {
type: [
[
{
type: Number,
},
],
],
},
});
const TestingMultiDimArraysModel = mongoose.model('TestingMultiDimArraysModel', schema);
async function main() {
await mongoose.connect(`mongodb://localhost:27017/`, {
dbName: 'verifyMASTER',
});
let testObj = new TestingMultiDimArraysModel({
intArray: [
[1, 2],
[3, 4],
],
});
await testObj.save();
testObj = await TestingMultiDimArraysModel.findById(testObj._id).orFail();
console.log('testobj', testObj);
//fails
// getChanges():
// {
// '$set': {
// 'intArray.$.0': [ [ undefined, undefined ], [ undefined, undefined ] ]
// },
// '$inc': { __v: 1 }
// }
// save Error:
// The positional operator did not find the match needed from the query.
// MongoServerError: The positional operator did not find the match needed from the query
testObj.intArray![0][0] = 9;
console.log('changes', inspect(testObj.getChanges(), undefined, Infinity));
await testObj.save();
testObj = await TestingMultiDimArraysModel.findById(testObj._id).orFail();
assertion(testObj.intArray![0][0] === 9);
await mongoose.disconnect();
}
main();