MorphiaOrg / MorphiaOrg/morphia

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

Open
#1,180 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

proposed
Dominant language
Java
Stars
1.7k
Forks
449
Avg merge
7m
Merged PRs (30d)
10

Description

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()
}

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 Morphia's datastore.find(SomeModel::class.java).filter("_id =", id) query path and the existing terminal operations. Determine how an existence check should behave for MongoDB-backed queries, then add the fluent behavior requested in the example and verify it against the current persistence-check use case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.