Reputation: 11062
I am using ReactiveMongo
in the Spring Boot
configured project.
@Document(collection = "tbl_created_service")
public class Services {
@Id
private ObjectId objectId;
private Long id;
// Getters and setters
}
public interface ServiceReactiveRepository extends ReactiveMongoRepository<Services, String>
{
}
public interface ServicesService {
Long addNewService(Services services);
}
@Service
public class ServicesServiceImpl implements ServicesService {
@Autowired
ServiceReactiveRepository serviceReactiveRepository;
@Override
public Long addNewService(Services servicesTypeDto) {
serviceReactiveRepository.save(servicesTypeDto);
return null;
}
spring:
profiles:
active: dev
---
spring:
profiles: dev
data.mongodb:
host: 127.0.0.1
port: 27017
database: dev
---
@SpringBootApplication
public class PartnersApplication {
public static void main(String[] args) {
SpringApplication.run(PartnersApplication.class, args);
}
}
When I am hitting the endpoint, I can see the data is binding and coming to ServicesServiceImpl.addNewService()
but somehow it's not creating a new collection in DB (If not exists) i.e. tbl_created_service
However, If I add the collection manually and hit the service, Then it's creating a new document in "tbl_created_service"
.
Is the right way to do it? or I am missing something?
Any hint would be appreciable :)
Upvotes: 1
Views: 669
Reputation: 13
just put this at your application.properties spring.data.mongodb.uri=URIconnection
this will work when you will use an MongoDb atlas. Just create cluster and connect get the Java URI link then put it in your property. When you run your application it will auto generate the collections declared at your Entity class.
Upvotes: 1