0

I am seeing this error when I try to write data to mongodb.

com.mongodb.commandFailureException: err msg: Bson field ‘authenticate.nonce’ is an unknown field. Code 40415

public void writeToMongo(BasicDBObject data){
    MongoCredential credential = MongoCredential.createMongoCRCredential(username, dbName, pwd);
    MongoClient client = new MongoClient(new ServerAddress(hostIp,port, Arrays.asList(credential)));
    database= client.getDB(dbName);
    collection= database.getCollection(“nameTable”);
    collection.save(data);
}

Anyone could help?

qt.qt
  • 19
  • 5
  • Does this answer your question? [MongoDB 40415: BSON field 'create.bsonType' is an unknown field](https://stackoverflow.com/questions/59660010/mongodb-40415-bson-field-create-bsontype-is-an-unknown-field) – Thomas Aug 25 '22 at 08:07
  • @Thomas hello there!! I hope so but the error message is different. – qt.qt Aug 25 '22 at 08:19
  • Yeah, because it's a field from the validator defined in _your_ database. – Thomas Aug 25 '22 at 08:30
  • What is the version of Java driver you are using? – prasad_ Aug 25 '22 at 08:34
  • @Thomas what is a validator? – qt.qt Aug 25 '22 at 08:34
  • `new MongoClient(..` - this is legacy version of using the `MongoClient`. Looks like the `new ServerAddress(` doesn't have the third param `Arrays.asList(credential)`. Does your code compile? – prasad_ Aug 25 '22 at 08:45

0 Answers0