[CSHARP-388] Duplicate element name 'cause' when map reducing Created: 07/Feb/12  Updated: 02/Apr/15  Resolved: 01/Mar/12

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

Type: Bug Priority: Major - P3
Reporter: Grégoire Seux Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: mapreduce
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

windows


Issue Links:
Related
related to CSHARP-404 Do not throw exception on dup fields ... Closed

 Description   

When mapreducing, a strange error appear sometimes. Here is the stacktrace :
System.InvalidOperationException: Duplicate element name 'cause'. at MongoDB.Bson.BsonDocument.Add(BsonElement element) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\ObjectModel\BsonDocument.cs:line 453
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\ObjectModel\BsonDocument.cs:line 720
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\ObjectModel\BsonDocument.cs:line 393
at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\BsonSerializer.cs:line 214
at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadFrom(BsonBuffer buffer, IBsonSerializationOptions serializationOptions) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoReplyMessage.cs:line 94
at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinaryReaderSettings readerSettings, IBsonSerializationOptions serializationOptions) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 386
at MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection, MongoRequestMessage message) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 263
at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 223
at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 126
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at MongoDB.Driver.MongoCollection.FindOneAs[TDocument](IMongoQuery query) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 498 at MongoDB.Driver.MongoCollection`1.FindOne(IMongoQuery query) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1639 at MongoDB.Driver.MongoDatabase.RunCommandAs(Type commandResultType, IMongoCommand command) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 891
at MongoDB.Driver.MongoDatabase.RunCommandAs[TCommandResult](IMongoCommand command) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 866
at MongoDB.Driver.MongoCollection.MapReduce(BsonJavaScript map, BsonJavaScript reduce, IMongoMapReduceOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1106 at MongoDB.Driver.MongoCollection.MapReduce(IMongoQuery query, BsonJavaScript map, BsonJavaScript reduce, IMongoMapReduceOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1127

I think this due to the driver incapicity to add several times the same field to a bsondocument.



 Comments   
Comment by Grégoire Seux [ 01/Mar/12 ]

ok thanks

Comment by Robert Stam [ 01/Mar/12 ]

Since the implementation of CSHARP-404 now allows BsonDocuments returned from the server to contain duplicate names, this should no longer be an issue even if the server does return more than one instance of the "cause" element.

Therefore I won't try to reproduce this anymore.

Comment by Grégoire Seux [ 27/Feb/12 ]

An example of data is :
{
"_id" : BinData(0,"YS5tp2cGAAAzMDg5Mw=="),
"category" : [

{ "h" : 1110547694, "colTp" : 1, "catName" : "Librairie > Livres > Street Art", "catType" : "NONE" }

],
"price" : 99.99
"lastTouch" : ISODate("2012-02-27T12:59:30.155Z"),
"partnerId" : 1639,
}

Comment by Grégoire Seux [ 27/Feb/12 ]

map = function() {
if (this.category !=null && this.recommendable != false) {
product = this;
this.category.forEach(function(value) {
emit(

{colTp:value.colTp, h:value.h, lT: [A DATE], name:value.catName, partnerId : product.partnerId}

,

{ sp :product.price, nbprod :1}

);
})
}
}

reduce = function(key,values)

{ var result = sp : 0, nbprod:0}

;
values.forEach(function(value)

{ result.sp += value.sp; result.nbprod += value.nbprod; }

);
return result;
}

Comment by Robert Stam [ 14/Feb/12 ]

Can you provide some sample data and the map/reduce functions needed to reproduce this?

I'm surprised the server allows you to create a document with duplicate field names (since JavaScript doesn't support that).

You are correct that the C# driver doesn't allow it.

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