deno.land / x / mongoose@6.7.5 / test / types / subdocuments.test.ts

subdocuments.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
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Schema, model, Model, Document, Types } from 'mongoose';
const childSchema: Schema = new Schema({ name: String });
const schema: Schema = new Schema({ child1: childSchema, child2: { type: childSchema, _id: false }, docarr1: [childSchema], docarr2: [{ type: childSchema, _id: false }]});
interface ITest extends Document { child1: { _id: Types.ObjectId, name: string }, child2: { name: string }}
const Test = model<ITest>('Test', schema);
const doc: ITest = new Test({});
doc.child1 = { _id: new Types.ObjectId(), name: 'test1' };doc.child2 = { name: 'test2' };

async function gh10597(): Promise<void> { interface IGameEvent { description: string; } type IGameEventDocument = IGameEvent & Types.Subdocument;
interface IGameDocument extends Document { name: string; events: IGameEventDocument[] } const schema = new Schema<IGameDocument>({ name: String, events: [{ description: String }] });
const GameModel = model<IGameDocument>('Game', schema);
const doc = await GameModel.findOne().orFail(); await doc.update({ events: [{ description: 'test' }] });}
function gh10674() { type Foo = { bar: string schedule: { date: string; hours: number; }[]; };
type FooModel = Model<Foo>;
const FooSchema = new Schema<Foo, FooModel, Foo>( { bar: { type: String }, schedule: { type: [ { date: { type: String, required: true }, hours: { type: Number, required: true } } ], required: true } } );}
async function gh10947(): Promise<void> { await Test.findOneAndUpdate({}, { child1: { name: 'foo' } });}
mongoose

Version Info

Tagged at
a year ago