I'm not sure how to phrase it, but I'd like to sort the following data in a way that the child messages are immediately below their parents.
{ "_id" : "oI", "msg" : "Hello", "ts" : ISODate("2019-09-20T01:01:43.749Z") },
{ "_id" : "z", "msg" : "can you hear me?", "ts" : ISODate("2019-09-20T01:01:46.569Z"), "tcount" : 3 },
{ "_id" : "wG", "msg" : "Undsen bichver 2", "ts" : ISODate("2019-09-20T02:00:58.254Z") },
{ "_id" : "BF", "msg" : "Undsen bichver 3", "ts" : ISODate("2019-09-20T02:01:06.784Z") },
{ "_id" : "Jq", "msg" : "Undsen bichver 4", "ts" : ISODate("2019-09-20T02:01:11.785Z") },
{ "_id" : "oP", "parentId" : "z", "msg" : "Test 1", "ts" : ISODate("2019-09-20T01:02:06.860Z") },
{ "_id" : "Mq", "parentId" : "z", "msg" : "Test 2", "ts" : ISODate("2019-09-20T01:05:37.173Z") },
{ "_id" : "Lq", "parentId" : "z", "msg" : "Test 3", "ts" : ISODate("2019-09-20T02:01:24.370Z") }
The sort I used to display the above result is this:
.sort({ "parentId": 1, "ts": 1 })
The result I want is this:
{ "_id" : "oI", "msg" : "Hello", "ts" : ISODate("2019-09-20T01:01:43.749Z") },
{ "_id" : "z", "msg" : "can you hear me?", "ts" : ISODate("2019-09-20T01:01:46.569Z"), "tcount" : 3 },
{ "_id" : "oP", "parentId" : "z", "msg" : "Test 1", "ts" : ISODate("2019-09-20T01:02:06.860Z") },
{ "_id" : "Mq", "parentId" : "z", "msg" : "Test 2", "ts" : ISODate("2019-09-20T01:05:37.173Z") },
{ "_id" : "Lq", "parentId" : "z", "msg" : "Test 3", "ts" : ISODate("2019-09-20T02:01:24.370Z") },
{ "_id" : "wG", "msg" : "Undsen bichver 2", "ts" : ISODate("2019-09-20T02:00:58.254Z") },
{ "_id" : "BF", "msg" : "Undsen bichver 3", "ts" : ISODate("2019-09-20T02:01:06.784Z") },
{ "_id" : "Jq", "msg" : "Undsen bichver 4", "ts" : ISODate("2019-09-20T02:01:11.785Z") }
Note the records with "parentId" : "z" are immediately below its parent ("_id" : "z")
Is it possible to do something like this?