0

着信要求からデータを取得し、基になるデータベースにカスタム クエリを発行し、そのクエリの結果をユーザーに返すインターセプターを作成したいと考えています。カスタム クエリの結果をユーザーに返す方法がわかりません。

これは私が試した例ですが、作成してプラグインに設定した応答ドキュメントがユーザーに返されません。

MongoInterceptor を使用してこれを行うことは可能ですか?

@RegisterPlugin(name = "exampleInterceptor",
        description = "example interceptor",
        interceptPoint = InterceptPoint.REQUEST_AFTER_AUTH,
        priority = 100)
public class ExampleInterceptor implements MongoInterceptor {

    @Override
    public void handle(MongoRequest request, MongoResponse response)
            throws Exception
    {
        String dbName = request.getDBName();
        String collName = request.getCollectionName();
        String[] pathInfo = request.getMappedRequestUri().split("/");
        if (pathInfo.length == 3) {
            String id = pathInfo[2];
            BsonDocument doc = new BsonDocument();
            doc.put("db", new BsonString(dbName));
            doc.put("collection", new BsonString(collName));
            doc.put("id", new BsonString(id));
            response.setContent(doc);
        }
    }

    @Override
    public boolean resolve(MongoRequest request, MongoResponse response) {
        return true;
    }
}

4

1 に答える 1