MongoDBTextFilterUsage

SUGGESTION

Performance

View source code on GitHub

Summary

Avoid MongoDB’s $text filter operator, as it can trigger heavy queries and even cause the server to run out of memory

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("MongoDBTextFilterUsage") to the enclosing element.

Disable this pattern completely by adding -Xep:MongoDBTextFilterUsage:OFF as compiler argument. Learn more.

Samples

Replacement

Shows the difference in example code before and after the bug pattern is applied.

Identification

Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains: comment is placed above any violating line.

import com.mongodb.client.model.Filters;
import com.mongodb.client.model.TextSearchOptions;

class A {
  void m() {
    Filters.eq("foo", "bar");
    // BUG: Diagnostic contains:
    Filters.text("foo");
    // BUG: Diagnostic contains:
    Filters.text("foo", new TextSearchOptions());
  }
}

Copyright © 2017-2024 Picnic Technologies BV