【问题标题】:How do i put an index on an array element using Mongoose如何使用 Mongoose 在数组元素上放置索引
【发布时间】:2013-04-30 16:01:50
【问题描述】:

如何在猫鼬中索引数组元素,这是我在架构中尝试的,但它不起作用

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

【问题讨论】:

  • 看起来不错。有什么不好的地方?

标签: mongodb mongoose


【解决方案1】:

[Number] 表示数字数组.... 如果想要一个没有定义类型的数组,你可以像这样使用混合类型:

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

或者

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

顺便说一下,这是一个 documentation 用于猫鼬模式类型

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 2021-06-15
    相关资源
    最近更新 更多