Display query results in descending order

#1

I have a xamarin.droid app that allows users to type in a message and that message is then displayed in a recyclerview. im now trying to get the messages to show in descending order by setting the query descending property to true but the rows in the recyclerview still return the messages in ascending format. can anyone pick up on what i have done wrong?

save message method:

public void SaveChatMessage(string msg,string user)
{
            var document = cbDB.CreateDocument();
            var properties = new Dictionary<string, object>{
                {"type","message"},
                {"message",msg},
                {"user",user},
                {"created",DateTime.Now.ToString()},
            };

            document.PutProperties(properties);

            var retrieveDocument = cbDB.GetDocument(document.Id);
            foreach(var props in retrieveDocument.Properties)
            {
                Log.Info("--DOCUMENT EVENT--","Document Properties: " + props.Key + " " + props.Value);
            }
    }

get chats:

public Query GetChats()
{
            var view = cbDB.GetView(dbView);

            if (view.Map == null)
            {
                view.SetMap((document, emitter) =>
                {
                    object type;
                    document.TryGetValue("type", out type);

                    if (docType.Equals((string)type))
                    {
                        emitter(document["created"], document);
                    }
                }, "1");
            }

            var query = view.CreateQuery();
            query.Descending = true;
            return query;
 }
#2

I suspect the problem may be the part where you actually show it in the view. Are you using the latest release, an older release, or master?

#3

Hi @borrrden

thanks for the response, can you clarify what you are referring to when asking about the release? are you talking about the couchbase lite component, android sdk or xamarin?

thanks

#4

The couchbase lite component is what I’m referring to.

#5

Hi @borrrden

While double checking the component version i saw that the component had an error. after reinstalling the component the query was returning in descending order.