Akhil Chandran
Akhil Chandran

Reputation: 460

Changing Mongoose schema type not working

I have a mongoose schema with a property which was a string array.

docs: [String]

I changed the type to an object array as follows

docs: [{ url: String, type: String }]

But when I create a new item, the docs field is still validated with the type string and the following error is thrown.

enter image description here

I even tried dropping the collection and it still not works.

Upvotes: 0

Views: 23

Answers (1)

Eldar B.
Eldar B.

Reputation: 1327

The brackets should be around the type, and not the entire object. As documented here, instead of your Schema being:

docs: [{ url: String, type: String }]

It should be

docs: { url: String, type: [String] }

Upvotes: 1

Related Questions