spring-projects / spring-projects/spring-data-mongodb

Queries in MongoTemplate Logs with ObjectId Format.

Open
#4,873 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: ideal-for-contribution theme: logging type: enhancement
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

When any operations made through MongoTemplate, I set the log level to DEBUG using the following configuration:
logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG.

This allows me to view the queries executed by MongoTemplate, which is helpful. However, the issue is that the query logs display ObjectId in the oid format, which cannot be directly executed in the MongoDB Compass client.

Is there a way to log the queries in the ObjectId("") format instead? I couldn’t find a solution for this issue. If a solution already exists, please let me know. If not, it would be great to have this functionality implemented.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing MongoTemplate DEBUG query logging and the existing MongoDB query rendering behavior. Look for tests covering logged query output and add coverage for ObjectId values. Done means queries are logged in executable ObjectId("...") format without changing query behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb, spring
Domain
databases, observability
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.