[CSHARP-807] Error: Can't extract geo keys from object, malformed geometry? Created: 27/Aug/13  Updated: 20/Mar/14  Resolved: 28/Aug/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Vladimir Bodurov Assignee: Robert Stam
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Attachments: Text File data1.txt    

 Description   

If I have geo-spherical index on "geo" field I can insert the attached document to mongo DB 2.5.1 but when I try to insert collection as

collection.Insert(BsonDocument.Parse(File.ReadAllText("data1.txt")))

I get error MongoDB.Driver.WriteConcernException : WriteConcern detected an error 'Can't extract geo keys from object, malformed geometry?:
at MongoDB.Driver.Operations.InsertOperation.Execute(MongoConnection connection)
at MongoDB.Driver.MongoCollection.InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options)
at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document, MongoInsertOptions options)
at Vlad.MongoGeoTests.Test.MiscTests.Test1() in MiscTests.cs: line 74

Why I get error when using the driver when I can insert it directly to mongo 2.5.1



 Comments   
Comment by Robert Stam [ 28/Aug/13 ]

OK. Thanks for the update.

Comment by Vladimir Bodurov [ 28/Aug/13 ]

I tried 2.5.2 and it works.
I guess you can close this ticket.

Comment by Robert Stam [ 28/Aug/13 ]

I am able to reproduce your error message when I run against a 2.5.0 server, but not against 2.5.1 or 2.5.2.

This is the test code I'm using:

if (collection.Exists()) { collection.Drop(); }
collection.EnsureIndex(IndexKeys.GeoSpatialSpherical("geo"));
 
var buildInfoCommand = new CommandDocument("buildinfo", true);
var buildInfoResult = server.GetDatabase("admin").RunCommand(buildInfoCommand);
Console.WriteLine("Server version: {0}", buildInfoResult.Response["version"]);
 
var indexes = collection.GetIndexes();
Console.WriteLine("Indexes: {0}", string.Join(", ", indexes.Select(i => i.Name)));
 
var json = File.ReadAllText("Data1.txt");
var document = BsonDocument.Parse(json);
collection.Insert(document);
 
Console.WriteLine("Insert succeeded");

This is the output when run against a 2.5.0 server:

Server version: 2.5.0
Indexes: _id_, geo_2dsphere
Unhandled exception:
MongoDB.Driver.WriteConcernException: WriteConcern detected an error 'Can't extract geo keys from object, malformed geometry?:{ type: "MultiPolygon", coordinates: [ [ [ [ -141.003, 69.52800000000001 ], [ -141.441, 69.575 ], ...

This is the output when run against a 2.5.1 server:

Server version: 2.5.1
Indexes: _id_, geo_2dsphere
Insert succeeded

This is the output when run against a 2.5.2 server:

Server version: 2.5.2
Indexes: _id_, geo_2dsphere
Insert succeeded

I also saw this warning in the server log when I ran the above test code against 2.5.1 or 2.5.2:

2013-08-27T23:13:20.553-0400 [conn1] warning: warning: log line attempted (12k)
over max size (10k), printing beginning and end ... insert of geo object generated lots of keys (312) consider creating larger buckets. obj={ _id: ObjectId('521d6ad07013202370d05ed2'), geo: { type: "MultiPolygon", coordinates: [ [ [ [ -141.003, 69.52800000000001 ], [ -141.441, 69.575 ], ...

Comment by Robert Stam [ 27/Aug/13 ]

Oops... I wasn't using the latest version of the server. Sorry.

I'm away from my development computer right now, but I will try again later tonight.

Comment by Vladimir Bodurov [ 27/Aug/13 ]

Did you try inserting it into 2.5.1? Yes I can insert it into 2.5.1 using the shell!

It is not expected to work on a version of mongo (db.version()) less than 2.5.1

Comment by Robert Stam [ 27/Aug/13 ]

I tried inserting the document you provided in Data1.txt using the mongo shell and I got the same error you are seeing from the C# driver:

> db.test.insert(doc)
Can't extract geo keys from object, malformed geometry?:{ type: "MultiPolygon",
coordinates: [ [ [ [ -141.003, 69.52800000000001 ], [ -141.441, 69.575 ], [ -142.04, 69.712 ], [ -142.467, 69.865 ], [ -143.026, 69.992 ], [ -143.542, 70.03400000000001 ], [ -143.974, 69.983 ], [ -144.55, 69.932 ], [ -145.308, 69.9240000000
... many more lines removed

Comment by Robert Stam [ 27/Aug/13 ]

Right, SERVER-8907 is the same ticket I referred to.

What do you mean when you say "I can insert the given polygon directly into mongo"? Do you mean using the MongoDB shell?

Comment by Vladimir Bodurov [ 27/Aug/13 ]

the result is:
{
"0" : {
"v" : 1,
"key" :

{ "_id" : 1 }

,
"ns" : "tests.unit_tests",
"name" : "id"
},
"1" : {
"v" : 1,
"key" :

{ "geo" : "2dsphere" }

,
"ns" : "tests.unit_tests",
"name" : "geo_2dsphere"
}
}

mongo 2.5.1 DOES support multi objects
https://jira.mongodb.org/browse/SERVER-8907

Event more so I can insert the given polygon directly into mongo

The problem is in the driver not in the mongodb
and if I try
col.Update(Query.EQ("_id", "hey"), Update.Replace(doc), UpdateFlags.Upsert);
I get
MongoDB.Driver.WriteConcernException : WriteConcern detected an error 'Can't extract geo keys from object, malformed geometry?
at MongoDB.Driver.Operations.WriteOperation.SendMessageWithWriteConcern(MongoConnection connection, BsonBuffer buffer, Int32 requestId, BsonBinaryReaderSettings readerSettings, BsonBinaryWriterSettings writerSettings, WriteConcern writeConcern)
at MongoDB.Driver.Operations.UpdateOperation.Execute(MongoConnection connection)
at MongoDB.Driver.MongoCollection.Update(IMongoQuery query, IMongoUpdate update, MongoUpdateOptions options)
at Vlad.MongoGeoTests.Test.MiscTests.Test1() in MiscTests.cs: line 73

Comment by Robert Stam [ 27/Aug/13 ]

It might just be that the server doesn't support MultiPolygon data. The following documentation page:

http://docs.mongodb.org/manual/core/2dsphere/

Only lists the following GeoJSON objects:

  • Point
  • LineString
  • Polgon

The following server ticket states that support for MultiPolygon was added in 2.5.1:

https://jira.mongodb.org/browse/SERVER-8907

Which is a bit odd since you mention that you were testing with 2.5.1.

Comment by Robert Stam [ 27/Aug/13 ]

Can you provide the result of running this command in the MongoDB shell:

> db.test.getIndexes()

Replacing "test" with the name of your collection. Knowing exactly how your index is defined will help me try to reproduce this.

Also, can you clarify what you mean by "I can insert it directly to mongo 2.5.1". Do you mean using the MongoDB shell?

Generated at Wed Feb 07 21:37:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.