【发布时间】:2020-11-17 19:38:42
【问题描述】:
为了提高我们的查询性能和 API 响应时间,我们通过聚合数据在 MongoDB 上创建了视图。但是,当我们尝试使用 Spring Mongo 模板使用视图时,会遇到一些问题,例如不支持视图。
Caused by: com.mongodb.MongoCommandException: Command failed with error 166 (CommandNotSupportedOnView): 'Namespace aiops.hostView is a view, not a collection' on server 192.168.20.166:30011. The full response is {"ok": 0.0, "errmsg": "Namespace aiops.hostView is a view, not a collection", "code": 166, "codeName": "CommandNotSupportedOnView"}
at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175)
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:303)
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:259)
Spring 是否支持开箱即用的 MongoDB 视图?任何例子都会有很大帮助!
提前谢谢你
【问题讨论】:
-
请问您是如何手动创建视图或使用 spring boot 编码的?我尝试使用 mongoTemlate 来做到这一点,但没有成功我使用了 mongoTemplate.executeCommand(create: "viewName" , viewOwn: "source" , pipeline : [ pip ] ) 我将不胜感激。
标签: spring mongodb spring-data-jpa