Sorting documents by embedded field array

14 views
Skip to first unread message

Mattia Agostinetto

unread,
May 20, 2016, 10:08:33 AM5/20/16
to Derby
Hi.
Can I order by messages.timestamp using Derby?

Example (Thread):

{
  id
: "id1"
  messages
: [{ timestamp: 4, subject ... }, { timestamp: 2, subject ... },{ timestamp: 3, subject ...}]
  name
: "A"
},
{
  id
: "id2"
  messages
: [{ timestamp: 1, subject ...}]
  name
: "B"
}


Thanks in advance.

PS - Mongo query

Thread.asc("messages.timestamp")
or
db.Thread.find().sort("{\"messages\":{\"timestamp\":1}}");


Nate Smith

unread,
May 20, 2016, 8:41:41 PM5/20/16
to der...@googlegroups.com

Sure. You can make pretty much any mongo query with the sharedb-mongo adapter. Derby doesn't understand mongo queries; it just passes them through as JSON and the adapter does all the db specific parsing.

We are working on updates for full mongo 3.2 support now, but in the current version you just have to use the $orderby parameter in your query

--
You received this message because you are subscribed to the Google Groups "Derby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to derbyjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages