MCPcopy Create free account
hub / github.com/Automattic/mongoose / DocumentArray

Function DocumentArray

lib/schema/documentarray.js:28–47  ·  view source on GitHub ↗

* SubdocsArray SchemaType constructor * * @param {String} key * @param {Schema} schema * @param {Object} options * @inherits SchemaArray * @api public

(key, schema, options)

Source from the content-addressed store, hash-verified

26 */
27
28function DocumentArray(key, schema, options) {
29 var EmbeddedDocument = _createConstructor(schema, options);
30
31 ArrayType.call(this, key, EmbeddedDocument, options);
32
33 this.schema = schema;
34 this.$isMongooseDocumentArray = true;
35 var fn = this.defaultValue;
36
37 if (!('defaultValue' in this) || fn !== void 0) {
38 this.default(function() {
39 var arr = fn.call(this);
40 if (!Array.isArray(arr)) {
41 arr = [arr];
42 }
43 // Leave it up to `cast()` to convert this to a documentarray
44 return arr;
45 });
46 }
47}
48
49/**
50 * This schema type's name, to defend against minifiers that mangle

Callers

nothing calls this directly

Calls 1

_createConstructorFunction · 0.85

Tested by

no test coverage detected