【发布时间】:2017-07-04 20:14:47
【问题描述】:
我遇到了 Spring Boot Data MongoDB 的问题。
我在下面用 dto 附加了我的代码。每次我尝试使用 GeoJsonPoint 对象插入新文档时,都会收到 com.mongodb.WriteConcernException: Write failed with error code 16804 and error message 'location object expected, location array not in correct format' 异常。
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.data.mongodb.core.index.GeoSpatialIndexed;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;
@Document(collection = "collection_2")
public class SingleBusStop {
@Id
private String id;
@GeoSpatialIndexed
private GeoJsonPoint location;
private DayType dayType;
private String lineNumber;
//getters, setters
}
我在同一个项目中获得了一些其他集合,我在其中插入了一些没有问题的数据(也使用 GeoJsonPoint)。出于某种原因,我无法将数据插入 collection_2。我正在使用 Mongo 3.4.2。我的 pom.xml 如下所示:
<groupId>pl.server.map</groupId>
<artifactId>Utils</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
更新
@GeoSpatialIndex
默认为2d索引,为避免出现问题,必须将其设置为2dsphere-如果出现此问题,只需在注释中切换索引类型:
@GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
【问题讨论】:
标签: java mongodb spring-boot