question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arrays without the option "type" or "items" makes array "Mixed" (adding array in array)

See original GitHub issue

Versions

  • NodeJS: 12.0.0
  • Typegoose(NPM): 7.x.x
  • Typegoose(GIT): commithash
  • mongoose: 5.9.20
  • mongodb: 3.5.9

What is the Problem?

Arrays prior to 7.1.0 are stored correctly. In versions later than 7.1 each element is nested in an own array:

Code Example

class Example {
  @prop()
  public arrayExample!: string[]
}

const arrayExample: ["1","2","3"]

new Example({arrayExample}).save()

My expectations in DB are:

{
   _id: ...,
   arrayExample: ["1","2","3"]
}

Its instead:

{
   _id: ...,
   arrayExample: [["1"],["2"],["3"]]
}

Do you know why it happenes?

no

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
smolinaricommented, Jun 23, 2020
class Something {
  @prop({ items: String })
  public languages?: string[];
}

Note the items:String.

Scott

4reactions
hasezoeycommented, Sep 15, 2020

@henhen724 please give an example on how you try to set it (btw, did you try to do type: [String]? when yes, this is only available since 7.4.0)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Q&A: How to create an array with mixed types in Swift?
While creating an array that contains instances of just one of the above two types is really straightforward — we just use either...
Read more >
Defining array with multiple types in TypeScript - Stack Overflow
This won't work with complex types with different properties, when you want to access a property available on only one of the types....
Read more >
Arrays - The Modern JavaScript Tutorial
If new Array is called with a single argument which is a number, then it creates an array without items, but with the...
Read more >
Chapter 10. Arrays
There are some situations in which an element of an array can be an array: if the element type is Object or Cloneable...
Read more >
Array Types - JavaScript. Flow
You can put any type within Array<Type> . 1 2 3, let arr1: Array< ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found