前言 一切操作都应该以官方文档为准,mongodb官网文档地址: https://www.mongodb.com/docs/ ,网上关于java操作mongodb的文章偏少,而且有些乱。这篇文章是在项目中使用mongodb后的一些总结,希望能帮到大家。 String linkUrl = "mongodb://" + url; if (hasAuth) { linkUrl = "mongodb://" + username + ":" + password + "@" + url + "/" + databaseName; } CodecRegistry pojoCodecRegistry = CodecRegistries.fromRegistries( MongoClientSettings.getDefaultCodecRegistry(), CodecRegistries.fromProviders(PojoCodecProvider.builder().automatic(true).build())); MongoClientSettings build =...