java.lang.IllegalArgumentException: Invalid BSON field name $uuid

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

Use replaceOne instead of updateOne


rp

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • Hello. I have a problem with Java UUID serialization. I'm having a UUID object and wanna serialize it: {code:title=Java|borderStyle=solid} JSON.serialize(myUuid) {code} Now when using this snipped in a more complex JSON as the following and parsing it with the code below the json, an error shows up. {code:title=json|borderStyle=solid} { "_id":"w1bEDr6", "server":"Lobby-01", "created":{ "$date":"2016-09-21T09:00:19.001Z" }, "messages":[ { "sender":{ "$uuid":"93ede72e-3ef0-42eb-a37b-62477df6497f" }, "message":"PLAYER_JOIN", "type":"EVENT", "timestamp":{ "$date":"2016-09-21T09:00:19.002Z" } }, { "sender":{ "$uuid":"93ede72e-3ef0-42eb-a37b-62477df6497f" }, "message":"/chatlog", "type":"COMMAND", "timestamp":{ "$date":"2016-09-21T09:00:23.821Z" } }, { "sender":{ "$uuid":"93ede72e-3ef0-42eb-a37b-62477df6497f" }, "message":"PLAYER_QUIT", "type":"EVENT", "timestamp":{ "$date":"2016-09-21T09:00:25.643Z" } } ] } {code} {code:title=Java|borderStyle=solid} Document.parse(json) {code} {code:title=Error|borderStyle=solid} java.lang.IllegalArgumentException: Invalid BSON field name $uuid at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:494) at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:188) at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:172) at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:189) at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:172) at org.bson.codecs.DocumentCodec.writeIterable(DocumentCodec.java:197) at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:170) at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:189) at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:131) at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29) at com.mongodb.connection.InsertCommandMessage.writeTheWrites(InsertCommandMessage.java:101) at com.mongodb.connection.InsertCommandMessage.writeTheWrites(InsertCommandMessage.java:43) at com.mongodb.connection.BaseWriteCommandMessage.encodeMessageBodyWithMetadata(BaseWriteCommandMessage.java:129) at com.mongodb.connection.RequestMessage.encodeWithMetadata(RequestMessage.java:160) at com.mongodb.connection.WriteCommandProtocol.sendMessage(WriteCommandProtocol.java:212) at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:101) at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:67) at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:37) at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159) at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286) at com.mongodb.connection.DefaultServerConnection.insertCommand(DefaultServerConnection.java:115) at com.mongodb.operation.MixedBulkWriteOperation$Run$2.executeWriteCommandProtocol(MixedBulkWriteOperation.java:455) at com.mongodb.operation.MixedBulkWriteOperation$Run$RunExecutor.execute(MixedBulkWriteOperation.java:646) at com.mongodb.operation.MixedBulkWriteOperation$Run.execute(MixedBulkWriteOperation.java:401) at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:179) at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:168) at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:168) [14/9133] at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:230) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221) at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:168) at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:74) at com.mongodb.Mongo.execute(Mongo.java:781) at com.mongodb.Mongo$2.execute(Mongo.java:764) at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:515) at com.mongodb.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:306) at com.mongodb.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:297) <rest of stacktrace removed> {code} Any idea what's going on here? Is this a bug or an error with my code?
    via by Sebastian Binder,
  • Exeption in MongoClient.update
    via GitHub by remi128
    ,
  • MongoDb upsert exception invalid BSON field
    via Stack Overflow by Aubin
    ,
  • Cannot use ENUM in profile schema
    via by axuan,
    • java.lang.IllegalArgumentException: Invalid BSON field name $uuid at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:494) at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:188) at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:172) at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:189) at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:172) at org.bson.codecs.DocumentCodec.writeIterable(DocumentCodec.java:197) at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:170) at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:189) at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:131) at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29) at com.mongodb.connection.InsertCommandMessage.writeTheWrites(InsertCommandMessage.java:101) at com.mongodb.connection.InsertCommandMessage.writeTheWrites(InsertCommandMessage.java:43) at com.mongodb.connection.BaseWriteCommandMessage.encodeMessageBodyWithMetadata(BaseWriteCommandMessage.java:129) at com.mongodb.connection.RequestMessage.encodeWithMetadata(RequestMessage.java:160) at com.mongodb.connection.WriteCommandProtocol.sendMessage(WriteCommandProtocol.java:212) at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:101) at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:67) at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:37) at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159) at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286) at com.mongodb.connection.DefaultServerConnection.insertCommand(DefaultServerConnection.java:115) at com.mongodb.operation.MixedBulkWriteOperation$Run$2.executeWriteCommandProtocol(MixedBulkWriteOperation.java:455) at com.mongodb.operation.MixedBulkWriteOperation$Run$RunExecutor.execute(MixedBulkWriteOperation.java:646) at com.mongodb.operation.MixedBulkWriteOperation$Run.execute(MixedBulkWriteOperation.java:401) at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:179) at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:168)

    Users with the same issue

    Unknown visitor1 times, last one,
    rp
    rp1 times, last one,
    Alireza Mohamadi
    Alireza Mohamadi5 times, last one,
    Unknown visitor2 times, last one,
    Unknown visitor1 times, last one,
    11 more bugmates