ts-mongoose
ts-mongoose copied to clipboard
how to define an array of array of number/string (2d array)?
Thanks for supplying this so great library.
in normal mongoose I can define like this
const blogSchema = new Schema({
data: [[Number]]
});
I have tried but failed
data: Type.array().of(Type.array().of(Type.string()))
How can I define this in ts-mongoose?
Following seems to be working:
Type.array({ required: true }).of(Type.array({ required: true }).of(Type.string())),
Also this:
Type.array().of(Type.array().of(Type.string())),
What type is returned for data
?
Thanks. @lchimaru .
It just throws a runtime exception
/Users/grimmer/git/v2/server/node_modules/mongoose/lib/schema.js:946
throw new TypeError('Invalid schema configuration: ' +
^
source-map-support.js:441
TypeError: Invalid schema configuration: `undefined` is not a valid type within the array `data`.See http://bit.ly/mongoose-schematypes for a list of valid schema types.
at Schema.interpretAsType (/Users/grimmer/git/v2/server/node_modules/mongoose/lib/schema.js:946:15)
at Schema.path (/Users/grimmer/git/v2/server/node_modules/mongoose/lib/schema.js:677:27)
at Schema.add (/Users/grimmer/git/v2/server/node_modules/mongoose/lib/schema.js:516:14)
at new Schema (/Users/grimmer/git/v2/server/node_modules/mongoose/lib/schema.js:129:10)
at Object.exports.createSchema (/Users/grimmer/git/v2/server/node_modules/ts-mongoose/createSchema.js:5:12)
at Object.<anonymous> (/Users/grimmer/git/v2/server/service/mongoose/User.ts:12:5)
at Module._compile (internal/modules/cjs/loader.js:1157:30)
at Module.m._compile (/Users/grimmer/git/v2/server/node_modules/ts-node/src/index.ts:536:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
at Object.require.extensions.<computed> [as .ts] (/Users/grimmer/git/v2/server/node_modules/ts-node/src/index.ts:539:12)
at Module.load (internal/modules/cjs/loader.js:1001:32)
at Function.Module._load (internal/modules/cjs/loader.js:900:14)
at Module.require (internal/modules/cjs/loader.js:1043:19)
at require (internal/modules/cjs/helpers.js:77:18)
The following writing method can works!
- Type.array().of(Type.array().of(Type.string()))
+ Type.array().of({})
My db data.