Skip to content

MongoTemplate DEBUG logging producing invalid output #5125

@jesmith17

Description

@jesmith17

Using spring-data-mongodb:3.4.0.

Running a custom query using the @Query annotation in my repository class. Full method looks like.

@Query(value="{'firstName': ?0, 'lastName':  ?1}")
    Page<Customer> searchCustomers(String firstName, String lastName, Pageable pageable);

When enabling debug logging for the MongoTemplate class, the logs output the following.

find using query: { "firstName" : "Josh", "lastName" : "Smith"} fields: Document{{}} sort: { "firstName" : "Josh", "lastName" : "Smith"} for class: class com.examples.mongobank.models.Customer in collection: customers

This method returns correctly, which proves that the logging statement is erroneous as if you tried to run this directly against the DB you would get this error.

Enterprise replLocal [direct: primary] mongobank> db.customers.find({ "firstName" : "Josh", "lastName" : "Smith"}).sort({"firstName":"Josh", "lastName":"Smith"});
MongoInvalidArgumentError: Invalid sort direction: "Josh"
Enterprise replLocal [direct: primary] mongobank>

This creates a problem when trying to triage issues with queries, because we can't trust that the logger is outputting the correct query.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions