Below, you query for an instance with an `id` of `"123"`, and then delete it, if found:

<BlockSwitcher>
<Block name="Java">

```java
QueryOptions queryOptions = null;
try {
    queryOptions = Where.identifier(Post.class, "123");
} catch (AmplifyException e) {
    Log.e("MyAmplifyApp", "Failed to construct QueryOptions with provided values for Where.identifier", e);
}

if (queryOptions != null) {
    Amplify.DataStore.query(Post.class, queryOptions,
        matches -> {
            if (matches.hasNext()) {
                Post post = matches.next();
                Amplify.DataStore.delete(post,
                    deleted -> Log.i("MyAmplifyApp", "Deleted a post."),
                    failure -> Log.e("MyAmplifyApp", "Delete failed.", failure)
                );
            }
        },
        failure -> Log.e("MyAmplifyApp", "Query failed.", failure)
    );
} 
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
Amplify.DataStore.query(Post::class.java, Where.identifier(Post::class.java, "123"),
    { matches ->
        if (matches.hasNext()) {
            val post = matches.next()
            Amplify.DataStore.delete(post,
                { Log.i("MyAmplifyApp", "Deleted a post.") },
                { Log.e("MyAmplifyApp", "Delete failed.", it) }
            )
        }
    },
    { Log.e("MyAmplifyApp", "Query failed.", it) }
)
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
Amplify.DataStore.query(Post::class, Where.identifier(Post::class.java, "123"))
    .catch { Log.e("MyAmplifyApp", "Query failed", it) }
    .onEach { Amplify.DataStore.delete(it) }
    .catch { Log.e("MyAmplifyApp", "Delete failed", it) }
    .collect { Log.i("MyAmplifyApp", "Deleted a post") }
```

</Block>
<Block name="RxJava">

```java
QueryOptions queryOptions = null;
try {
    queryOptions = Where.identifier(Post.class, "123");
} catch (AmplifyException e) {
    Log.e("MyAmplifyApp", "Failed to construct QueryOptions with provided values for Where.identifier", e);
}

if (queryOptions != null) {
    RxAmplify.DataStore.query(Post.class, queryOptions)
        .flatMapCompletable(RxAmplify.DataStore::delete)
        .subscribe(
            () -> Log.i("MyAmplifyApp", "Deleted a post."),
            failure -> Log.e("MyAmplifyApp", "Delete failed.", failure)
        );
}
```

</Block>
</BlockSwitcher>

To conditionally delete an instance, pass an instance and a predicate into `Amplify.DataStore.delete()`.
In the example below, posts are deleted only if their `rating` is greater than `4`:

<BlockSwitcher>
<Block name="Java">

```java
Amplify.DataStore.query(Post.class,
        matches -> {
            if (matches.hasNext()) {
                Post post = matches.next();
                Amplify.DataStore.delete(post, Where.matches(Post.RATING.gt(4)).getQueryPredicate(),
                        deleted -> Log.i("MyAmplifyApp", "Deleted a post."),
                        failure -> Log.e("MyAmplifyApp", "Delete failed.", failure)
                );
            }
        },
        failure -> Log.e("MyAmplifyApp", "Query failed.", failure)
);
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
Amplify.DataStore.query(Post::class.java,
    { matches ->
        if (matches.hasNext()) {
            val post = matches.next()
            Amplify.DataStore.delete(post, Where.matches(Post.RATING.gt(4)).queryPredicate,
                { Log.i("MyAmplifyApp", "Deleted a post.") },
                { Log.e("MyAmplifyApp", "Delete failed.", it) }
            )
        }
    },
    { Log.e("MyAmplifyApp", "Query failed.", it) }
)
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
Amplify.DataStore.query(Post::class)
    .catch { Log.e("MyAmplifyApp", "Query failed", it) }
    .onEach { Amplify.DataStore.delete(it, Where.matches(Post.RATING.gt(4)).queryPredicate) }
    .catch { Log.e("MyAmplifyApp", "Delete failed", it) }
    .collect { Log.i("MyAmplifyApp", "Deleted a post") }
```

</Block>
<Block name="RxJava">

```java
RxAmplify.DataStore.query(
    Post.class,
    Where.matches(Post.RATING.gt(4)))
    .subscribe(
            post -> RxAmplify.DataStore.delete(post, Where.matches(Post.RATING.gt(4)).getQueryPredicate())
                    .subscribe(
                            () -> Log.i("MyAmplifyApp", "Deleted a post."),
                            failure -> Log.e("MyAmplifyApp", "Delete failed.", failure)
                    ),
            failure -> Log.e("MyAmplifyApp", "Query failed.", failure)
    );
```

</Block>
</BlockSwitcher>
