MCPcopy
hub / github.com/Automattic/mongoose / createWithMapOfSubdocs

Function createWithMapOfSubdocs

test/types/create.test.ts:155–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153}
154
155async function createWithMapOfSubdocs() {
156 const schema = new Schema({
157 name: String,
158 subdocMap: {
159 type: Map,
160 of: new Schema({ prop: { type: String, required: true } })
161 }
162 });
163 const TestModel = model('Test', schema);
164
165 const doc = await TestModel.create({ name: 'test', subdocMap: { taco: { prop: 'beef' } } });
166 expect(doc.name).type.toBe<string | null | undefined>();
167 expect(doc.subdocMap!.get('taco')!.prop).type.toBe<string>();
168
169 const doc2 = await TestModel.create({ name: 'test', subdocMap: [['taco', { prop: 'beef' }]] });
170 expect(doc2.name).type.toBe<string | null | undefined>();
171 expect(doc2.subdocMap!.get('taco')!.prop).type.toBe<string>();
172}
173
174async function createWithSubdocs() {
175 const schema = new Schema({

Callers

nothing calls this directly

Calls 3

modelFunction · 0.85
createMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…