spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Queries in MongoTemplate Logs with ObjectId Format.

Open ganeshbabugb opened this issue 10 months ago • 4 comments

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.

ganeshbabugb avatar Jan 14 '25 12:01 ganeshbabugb

We use Document.toJson() which internally uses JsonMode.RELAXED. Logging is a recurring theme. Do you want to investigate how to introduce JsonWriterSettings for logging purposes in MongoTemplate and ReactiveMongoTemplate?

mp911de avatar Jan 14 '25 15:01 mp911de

Yes, exactly what i am looking for.

ganeshbabugb avatar Jan 15 '25 05:01 ganeshbabugb

@ganeshbabugb and/or @mp911de ,

I would like to provide a pull request. It is like starting from "scratch", because there is no pull request or feature branch, right ?

rfelgent avatar Mar 06 '25 07:03 rfelgent

It is like starting from "scratch", because there is no pull request or feature branch, right ?

Exactly.

mp911de avatar Mar 06 '25 09:03 mp911de