MongoDB 想要映射对象特征的 GeoJSON BoundingBox 属性
MongoDB wants GeoJSON BoundingBox property of object Feature to be mapped
我想使用 GeoJSON 特征对象来表示我 中的位置ASP.Net 核心网站 API。我习惯于使用以下代码将样本数据插入到我的 MongoDb 数据库:
db.Measurements.insertMany([{
'Degree': 1.3,
'Location': {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [49.04852804478914, 9.173037938241464]
},
"properties": {
"name": "Neckar"
}
},
'MeasurementTime': ISODate("2020-03-10T10:50:42.389Z"),
'MachineId': '6dsfal865kkl34l32'
}, ...
为了映射此数据,我在下面编写了模型 class,following the instructions in Docs。
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using BAMCIS.GeoJSON;
using System;
public class Measurement
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonElement]
public decimal PollutionDegree { get; set; }
[BsonElement]
public Feature Location { get; set; }
//
[BsonElement]
[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
public DateTime MeasurementTime { get; set; }
[BsonElement]
public string MachineId { get; set; }
}
API 在没有 Location 的情况下工作正常,但是当我取消注释这两行并将数据添加到我的测量集合中时,我收到以下错误消息:
An exception of type 'System.FormatException' occurred in MongoDB.Bson.dll but
was not handled in user code: 'An error occurred while deserializing the Location
property of class API.Models.Measurement: Member 'BoundingBox' is not mapped.'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception MongoDB.Bson.BsonSerializationException : Member 'BoundingBox' is not mapped.
at MongoDB.Bson.Serialization.BsonCreatorMap.Freeze()
at MongoDB.Bson.Serialization.BsonClassMap.Freeze()
at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(Type classType)
at MongoDB.Bson.Serialization.BsonClassMapSerializationProvider.GetSerializer(Type type, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Bson.Serialization.BsonSerializerRegistry.CreateSerializer(Type type)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer(Type type)
at MongoDB.Bson.Serialization.BsonSerializer.LookupSerializer(Type type)
at MongoDB.Bson.Serialization.BsonMemberMap.GetSerializer()
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeMemberValue(BsonDeserializationContext context, BsonMemberMap memberMap)
现在,我不明白这个错误信息如下:
它表示由于缺少 BoundingBox 属性 而引发异常。但是 BoundingBox 似乎并不是特征对象的强制性 属性。
根据 RFC696,边界框不是 properties that a Feature Object has to possess. Moreover, a Bounding Box is described as it MAY be a part of a Feature object 之一。
如果有人能解释需要做什么才能正确读取数据,我将不胜感激。
MongoDB 仅支持 GeoJSON 对象的一个子集。请参阅文档中的 GeoJSON Object。
这是一个简短的列表:
- 点
- 线串
- 多边形
- 多点
- 多线串
- 多边形
- 几何集合
我想使用 GeoJSON 特征对象来表示我 中的位置ASP.Net 核心网站 API。我习惯于使用以下代码将样本数据插入到我的 MongoDb 数据库:
db.Measurements.insertMany([{
'Degree': 1.3,
'Location': {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [49.04852804478914, 9.173037938241464]
},
"properties": {
"name": "Neckar"
}
},
'MeasurementTime': ISODate("2020-03-10T10:50:42.389Z"),
'MachineId': '6dsfal865kkl34l32'
}, ...
为了映射此数据,我在下面编写了模型 class,following the instructions in Docs。
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using BAMCIS.GeoJSON;
using System;
public class Measurement
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonElement]
public decimal PollutionDegree { get; set; }
[BsonElement]
public Feature Location { get; set; }
//
[BsonElement]
[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
public DateTime MeasurementTime { get; set; }
[BsonElement]
public string MachineId { get; set; }
}
API 在没有 Location 的情况下工作正常,但是当我取消注释这两行并将数据添加到我的测量集合中时,我收到以下错误消息:
An exception of type 'System.FormatException' occurred in MongoDB.Bson.dll but
was not handled in user code: 'An error occurred while deserializing the Location
property of class API.Models.Measurement: Member 'BoundingBox' is not mapped.'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception MongoDB.Bson.BsonSerializationException : Member 'BoundingBox' is not mapped.
at MongoDB.Bson.Serialization.BsonCreatorMap.Freeze()
at MongoDB.Bson.Serialization.BsonClassMap.Freeze()
at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(Type classType)
at MongoDB.Bson.Serialization.BsonClassMapSerializationProvider.GetSerializer(Type type, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Bson.Serialization.BsonSerializerRegistry.CreateSerializer(Type type)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer(Type type)
at MongoDB.Bson.Serialization.BsonSerializer.LookupSerializer(Type type)
at MongoDB.Bson.Serialization.BsonMemberMap.GetSerializer()
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeMemberValue(BsonDeserializationContext context, BsonMemberMap memberMap)
现在,我不明白这个错误信息如下:
它表示由于缺少 BoundingBox 属性 而引发异常。但是 BoundingBox 似乎并不是特征对象的强制性 属性。
根据 RFC696,边界框不是 properties that a Feature Object has to possess. Moreover, a Bounding Box is described as it MAY be a part of a Feature object 之一。
如果有人能解释需要做什么才能正确读取数据,我将不胜感激。
MongoDB 仅支持 GeoJSON 对象的一个子集。请参阅文档中的 GeoJSON Object。
这是一个简短的列表:
- 点
- 线串
- 多边形
- 多点
- 多线串
- 多边形
- 几何集合