I have a Spring Boot GraphQL service which reads from Mongo.
I've noticed that if my MongoDB document ID has ObjectID e.g. "_id": ObjectID("5e5605150") I'm able to get results from doing myRepository.findById(myId).
However if that id is just a string like "_id": "5e5605150" then findById returns nothing.
The repository looks like this:
@Repository
interface MyRepository : MongoRepository<Song, String>
And that Song looks like this:
@Document(collection = Song.COLLECTION)
data class Song(
@Id
val id: String,
val title: String
) {
companion object {
const val COLLECTION: String = "song"
}
}
Any ideas?
Thanks.