Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create view in mongodb using spring data mongo db

How to create view in mongodb using spring data mongodb? Thanks

like image 605
Deni Husni Fahri Rizal Avatar asked Sep 19 '25 03:09

Deni Husni Fahri Rizal


1 Answers

You can inject bean of type org.springframework.data.mongodb.core.MongoTemplate where you need it and use one of its methods executeCommand, for example executeCommand(String jsonCommand) in folowing manner:

mongoTemplate.executeCommand("{ create: <view>, viewOn: <source>, pipeline: <pipeline> }");
like image 195
Andrey Petrenko Avatar answered Sep 21 '25 19:09

Andrey Petrenko