How to create view in mongodb using spring data mongo db

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

Upvotes: 4

Views: 1627

Answers (1)

Andrey Petrenko
Andrey Petrenko

Reputation: 76

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> }");

Upvotes: 3

Related Questions