有吗
对于mongodb中的2dsphere几何索引?
mongodb能阻止存储
几何图形(空列表,空dict)?
测试用例:
$ mongo
MongoDB shell version v4.0.6
...
> use geotest
switched to db geotest
> db.places.createIndex({'geometry': '2dsphere'})
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
……到目前为止还不错。
> db.places.insert({'geometry': [[]]}) // this fails -> good
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 16755,
"errmsg" : "Can't extract geo keys: { _id: ObjectId('5c8a483bcebc3f30972cb9ea'), geometry: [ [] ] } Point must only contain numeric elements"
}
})
…很高兴这次失败了,但是:
> db.places.insert({'geometry': []}) // can I make mongo fail here too?
WriteResult({ "nInserted" : 1 })
> db.places.insert({'geometry': {}}) // and here?
WriteResult({ "nInserted" : 1 })
> db.places.insert({'geometry': null}) // how about this one?
WriteResult({ "nInserted" : 1 })
> db.places.find()
{ "_id" : ObjectId("5c8a4840cebc3f30972cb9eb"), "geometry" : [ ] }
{ "_id" : ObjectId("5c8a4843cebc3f30972cb9ec"), "geometry" : { } }
{ "_id" : ObjectId("5c8a4b23cebc3f30972cb9ee"), "geometry" : null }