猫鼬,索引位置数组 [英] Mongoose, index locations array

查看:64
本文介绍了猫鼬,索引位置数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文档中有一个位置数组,我想在该数组上添加2dSpere索引.有可能吗?

I have an array of locations in a document and I want to add a 2dSpere index on that array. Is that possible?

var LocationSchema = new Schema({
  type: { type: String, required: true },
  geometry: {
    type: { type: String, required: true },
    coordinates: { type: Array, required: true}
  },
  properties: Schema.Types.Mixed
});

// Collection to hold users
var UserSchema = new Schema({
    username: { type: String, required: true, unique: true },
    locations: [LocationSchema]
  },{ 
    versionKey: false
  }
);

如何在locations数组中的geometry字段上添加2DSphere索引?

How do I add a 2DSphere index on the geometry field in the locations array?

推荐答案

https://github.com/LearnBoost/mongoose/blob/master/examples/geospatial/geoJSONSchema.js#L19

LocationSchema.index({'geometry':'2dsphere'});

LocationSchema.index({ 'geometry' : '2dsphere' });

这篇关于猫鼬,索引位置数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆