Owais F
Owais F

Reputation: 55

How do i put an index on an array element using Mongoose

How do I index an array element in mongoose, this is what i am trying in my schema, but its not working

locations : [{ 
    loc: { type: [Number], index: '2d'}
 }]

Upvotes: 0

Views: 2959

Answers (1)

walid
walid

Reputation: 492

[Number] means array of numbers.... If want an array with out define the type you can use Mixed type like this :

loc: { type: [], index: '2d'}

Or

loc: { type: Schema.Types.Mixed, index: '2d'}

And by the way this is a documentation for mongoose schema types

Upvotes: 2

Related Questions