morphia icon indicating copy to clipboard operation
morphia copied to clipboard

Morphia could use a more fluent way to check if a data is persisted.

Open jackmiras opened this issue 7 years ago • 0 comments

Morphia: 1.3 JDK: 8 Mongodb: 3.4

Lately I've been using Morphia in combination with Sparkjava and Kotlin to build some REST APIs and often I have to check of data exists on the database before perform some operations over data that have references to another other data in other collections. And because of that I think the would be interesting if Morphia could use a more fluent way to check if some data is persisted or not in MongoDB.

Currently if we have to perform this kind of check we have to do something like:

fun isAlreadyPersisted(id: String) {
    datastore.find(SomeModel::class.java).filter("_id =", id) != null
}

I think that not just me but other developers would be more pleased if we get some syntax sugar directly from Morphia and write this kind of code like:

fun isAlreadyPersisted(id: String) {
    datastore.find(SomeModel::class.java).filter("_id =", id).exists()
}

jackmiras avatar Jul 19 '17 21:07 jackmiras