Получение только одного документа из Rethinkdb - PullRequest
0 голосов
/ 06 апреля 2019

Я хочу получить только 1 элемент из RethinkDB table, но, похоже, я не могу. Я пробовал с RunCursor, но я не могу использовать его с OrderBy, как говорит API. Я также не могу использовать Nth для оптимизации, хотя мой возвращаемый тип все еще должен быть массивом.

ПОКО

class KnownMessage{
   public long timestamp1{get;set;}
}

Метод 1: с RunResult

KnownMessage[] lastFinishedGame = await r.Db(Constants.DB_NAME)
                .Table(Constants.MESSAGE_TABLE)
                .Filter([some filtering])
                .OrderBy("timestamp1")
                .Nth(0)
                .RunResultAsync<KnownMessage[]>(this.con);

Error

Message: Newtonsoft.Json.JsonSerializationException : Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Server.Domain.KnownMessage]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'r[0].data'.

Method2 с RunCursor:

 Cursor<KnownMessage> lastFinishedGame = await r.Db(Constants.DB_NAME)
                .Table(Constants.MESSAGE_TABLE)
                .Filter([some filtering])
                .OrderBy("timestamp1")
                .Nth(0)
                .RunCursorAsync<KnownMessage>(this.con);

Error

The query response cannot be converted to a Cursor<T>. The run helper works with SUCCESS_SEQUENCE or SUCCESS_PARTIAL results. The server response was SUCCESS_ATOM. If the server response can be handled by this run method check T. Otherwise, if the server response cannot be handled by this run helper use `.RunAtom<T>` or `.RunResult<T>`.

Дело в том, что я ожидаю, что будет возвращен только один документ, и кажется, что нет никакого способа выразить это, кроме как с помощью nth, который все еще разрешается вокруг коллекции.

P.S Я не хочу оборачивать мой массив в другой объект!

...