Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to define an array of array of number/string (2d array)? #40

Open
grimmer0125 opened this issue Dec 18, 2019 · 3 comments
Open

how to define an array of array of number/string (2d array)? #40

grimmer0125 opened this issue Dec 18, 2019 · 3 comments
Labels
Question Further information is requested

Comments

@grimmer0125
Copy link

grimmer0125 commented Dec 18, 2019

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?

@lchimaru
Copy link
Collaborator

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?

@lchimaru lchimaru added the Question Further information is requested label Feb 20, 2020
@grimmer0125
Copy link
Author

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)

@yejimeiming
Copy link

yejimeiming commented Mar 19, 2024

The following writing method can works!

- Type.array().of(Type.array().of(Type.string()))
+ Type.array().of({})

My db data.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants