Aasawari
(Aasawari Sahasrabuddhe)
2
Hi @Nishat_Kumar4 and welcome to the community forum!!
I tried to implement the below code in spring boot and t works well for me.
Service class:
public Document findAndModify(String objectId) {
Document query = new Document("_id", new ObjectId(objectId));
Document update = new Document("$inc", new Document("lastIssuedTokenNo", 1));
Document options = new Document("returnDocument", "after");
return collection.findOneAndUpdate( query, update);
}
Main class:
@SpringBootApplication
public class AtlasSearchApplication {
public static void main(String[] args) {
String uri = "mongodb+srv://theuser:pwd@cluster0.k5dqp.mongodb.net/?retryWrites=true&w=majority&appName=cluster0";
try (MongoClient mongoClient = MongoClients.create(uri)) {
//MongoDatabase database = mongoClient.getDatabase("test");
MovieAtlasSearchService searchService = new MovieAtlasSearchService(new MongoTemplate(mongoClient, "test"));
Document findAndModify = searchService.findAndModify("6085c24f54b3444dd3fccc19");
System.out.println("Result " + findAndModify);
}}}
Could you help me with the error message that you are seeing while using the above code?
Regards
Aasawari