Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28975

Cannot remove document with 2dsphere partialFilter index

    • Fully Compatible
    • ALL
    • Hide
      // Create collection with partial 2dsphere index (condition is geometry_status >= 0) 
      db.test.createIndex(
          {"geoJson": "2dsphere"},
          { partialFilterExpression: {"geometry_status": {$gte:0}}}
      );
      // Insert document that doesn't meet partial index condition
      db.test.insert({
      		"_id": ObjectId('58f8e5e06758c605c09e9110'),
      		"geometry_status" : -1,
              "geoJson" : {
                  "type" : "Polygon",
                  "coordinates" : [ 
                      [ 
                          [ 
                              5.86121301988361, 
                              51.9128247961245
                          ], 
                          [ 
                              5.86121303441693, 
                              51.9128247960658
                          ], 
                          [ 
                              5.86121306203623, 
                              51.9128260363524
                          ], 
                          [ 
                              5.86077631455415, 
                              51.9128299191492
                          ], 
                          [ 
                              5.86076411163462, 
                              51.9122347660331
                          ], 
                          [ 
                              5.8612026892498, 
                              51.9122313253
                          ], 
                          [ 
                              5.8612136159931, 
                              51.912764202971
                          ], 
                          [ 
                              5.8613461964441, 
                              51.9127630207468
                          ], 
                          [ 
                              5.86134760592148, 
                              51.9128235878296
                          ], 
                          [ 
                              5.86121486552018, 
                              51.9128247796886
                          ], 
                          [ 
                              5.86121303441693, 
                              51.9128247960658
                          ], 
                          [ 
                              5.86121301988361, 
                              51.9128247961245
                          ]
                      ]
                  ]
              }});
      // Remove this document
      db.test.remove({"_id": ObjectId('58f8e5e06758c605c09e9110')});
      // Error
      
      Show
      // Create collection with partial 2dsphere index (condition is geometry_status >= 0) db.test.createIndex( { "geoJson" : "2dsphere" }, { partialFilterExpression: { "geometry_status" : {$gte:0}}} ); // Insert document that doesn't meet partial index condition db.test.insert({ "_id" : ObjectId( '58f8e5e06758c605c09e9110' ), "geometry_status" : -1, "geoJson" : { "type" : "Polygon" , "coordinates" : [ [ [ 5.86121301988361, 51.9128247961245 ], [ 5.86121303441693, 51.9128247960658 ], [ 5.86121306203623, 51.9128260363524 ], [ 5.86077631455415, 51.9128299191492 ], [ 5.86076411163462, 51.9122347660331 ], [ 5.8612026892498, 51.9122313253 ], [ 5.8612136159931, 51.912764202971 ], [ 5.8613461964441, 51.9127630207468 ], [ 5.86134760592148, 51.9128235878296 ], [ 5.86121486552018, 51.9128247796886 ], [ 5.86121303441693, 51.9128247960658 ], [ 5.86121301988361, 51.9128247961245 ] ] ] }}); // Remove this document db.test.remove({ "_id" : ObjectId( '58f8e5e06758c605c09e9110' )}); // Error
    • Storage 2018-02-12

      Hello,

      unexpected error occurred while trying to remove document that contains invalid geoJson from collection with partial index:

      WriteResult({
      	"nRemoved" : 0,
      	"writeError" : {
      		"code" : 16755,
      		"errmsg" : "Can't extract geo keys: { _id: ObjectId('58f8e5e06758c605c09e9110'), geometry_status: -1.0, geoJson: { type: \"Polygon\", coordinates: [ [ [ 5.86121301988361, 51.9128247961245 ], [ 5.86121303441693, 51.9128247960658 ], [ 5.86121306203623, 51.9128260363524 ], [ 5.86077631455415, 51.9128299191492 ], [ 5.86076411163462, 51.9122347660331 ], [ 5.8612026892498, 51.9122313253 ], [ 5.8612136159931, 51.912764202971 ], [ 5.8613461964441, 51.9127630207468 ], [ 5.86134760592148, 51.9128235878296 ], [ 5.86121486552018, 51.9128247796886 ], [ 5.86121303441693, 51.9128247960658 ], [ 5.86121301988361, 51.9128247961245 ] ] ] } }  Loop is not valid: [ [ 5.86121301988361, 51.9128247961245 ], [ 5.86121303441693, 51.9128247960658 ], [ 5.86121306203623, 51.9128260363524 ], [ 5.86077631455415, 51.9128299191492 ], [ 5.86076411163462, 51.9122347660331 ], [ 5.8612026892498, 51.9122313253 ], [ 5.8612136159931, 51.912764202971 ], [ 5.8613461964441, 51.9127630207468 ], [ 5.86134760592148, 51.9128235878296 ], [ 5.86121486552018, 51.9128247796886 ], [ 5.86121303441693, 51.9128247960658 ], [ 5.86121301988361, 51.9128247961245 ] ] Duplicate vertices: 1 and 10"
      	}
      })
      

      Partial index is 2dsphere with condition geometry_status >= 0. Inserted document has invalid goeJson but geometry_status = -1 so it can be inserted. But cannot be removed.

            Assignee:
            louis.williams@mongodb.com Louis Williams
            Reporter:
            andrei.belashou Andrei Belashou
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: