Updated Video.java and VideoRepository to use String for Id.#40
Open
rbramwell wants to merge 2 commits intojuleswhite:masterfrom
Open
Updated Video.java and VideoRepository to use String for Id.#40rbramwell wants to merge 2 commits intojuleswhite:masterfrom
rbramwell wants to merge 2 commits intojuleswhite:masterfrom
Conversation
MongoDB's auto generated ObjectId consists of alphanumeric characters and hyphens '-'. When a long is used as the datatype for the Id, Spring Data MongoDB will issue an update/overwrite a single document in MongoDB with '_Id': NumberLong(0).
Output from mongo shell (Id as long):
db.video.find().pretty()
{
"_id" : NumberLong(0),
"_class" : "org.magnum.mobilecloud.video.repository.Video",
"name" : "Video-3a3b3158-9517-48c4-bdbd-718374e296bd",
"url" : "http://coursera.org/some/video-3a3b3158-9517-48c4-bdbd-718374e296bd",
"duration" : NumberLong(2880000)
}
This differs from the desired outcome which is to create a new (additional) document on subsequent calls to src / test / java / org / magnum / mobilecloud / integration / test / VideoSvcClientApiTest.java
Output from mongo shell (Id as String in 2nd document):
db.video.find().pretty()
{
"_id" : NumberLong(0),
"_class" : "org.magnum.mobilecloud.video.repository.Video",
"name" : "Video-3a3b3158-9517-48c4-bdbd-718374e296bd",
"url" : "http://coursera.org/some/video-3a3b3158-9517-48c4-bdbd-718374e296bd",
"duration" : NumberLong(2880000)
}
{
"_id" : ObjectId("545cba6444ae69b880ba589b"),
"_class" : "org.magnum.mobilecloud.video.repository.Video",
"name" : "Video-a820232d-dca3-4754-8962-f5355e408d61",
"url" : "http://coursera.org/some/video-a820232d-dca3-4754-8962-f5355e408d61",
"duration" : NumberLong(60000)
}
Updated VideoRepository.java to extend MongoRepository<Video, String> instead of MongoRepository<Video, Long>. This is in line with change to Id as String insteaf og long.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
'Id' needs to be String in order for Spring Data JPA to correctly assign an allow MongoDB to automatically generate an ObjectId('...') and return to Spring Data JPA.