I would like to limit the number of nested objects inside a Rethinkdb query. Suppose I have conversations with nested messages.
[conversations]
[{
id: "fgh675",
name: "Some conversation",
messages: [{
id:"jhu432",
contents: "Hello world!",
createdAt: "2016-01-01 00:01:01"
},
{
id:"bgj876",
contents: "Hello earth",
createdAt: "2016-01-01 00:01:01"
}]
}]
How can i limit the number of messages objects ?
Event better, how can i write a query returning only the last message
.merge(function(c) { return {msg: c("messages").slice(-1)}; })
, but I cant find how to order messages first... (would that query be efficient if there are many messages) ?