I’m searching as such:
var options = {
where: {
text: {
[Op.like]: '%' + query + '%'
}
}
};
Post.findAll(options).then((r)=>{
Then sort the results based on when they were created:
if(sort == 'new'){
r=r.sort(function (a, b) {
return a.created.getTime() - b.created.getTime();
});
}
What comes out:

This is entirely out of order.
A few things:
- The sort function IS called
- I’ve tried just doing
r.sort not r=r.sort
- The
.created is always valid and is set with DataTypes.Now
- This is the same for doing any sort with it
What the search outputs before filtering:
[
Post {
dataValues: {
id: 1,
text: 'Cheese is great! You should totally eat it.',
creator: 1,
created: 2022-04-05T09:15:39.102Z,
likes: '[1]',
repliesLastID: 1,
replies: '[{"id":1,"author":1,"text":"cheese","likes":[]}]',
createdAt: 2022-04-05T09:15:39.103Z,
updatedAt: 2022-04-06T06:23:18.355Z
},
_previousDataValues: {
id: 1,
text: 'Cheese is great! You should totally eat it.',
creator: 1,
created: 2022-04-05T09:15:39.102Z,
likes: '[1]',
repliesLastID: 1,
replies: '[{"id":1,"author":1,"text":"cheese","likes":[]}]',
createdAt: 2022-04-05T09:15:39.103Z,
updatedAt: 2022-04-06T06:23:18.355Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 2,
text: "Access granted. No longer stuck on cheese.social's weird /welcome.n" +
'This is a historic day for all.',
creator: 1,
created: 2022-04-08T06:29:22.226Z,
likes: '[1,2]',
repliesLastID: 1,
replies: '[]',
createdAt: 2022-04-08T06:29:22.227Z,
updatedAt: 2022-04-09T04:27:43.171Z
},
_previousDataValues: {
id: 2,
text: "Access granted. No longer stuck on cheese.social's weird /welcome.n" +
'This is a historic day for all.',
creator: 1,
created: 2022-04-08T06:29:22.226Z,
likes: '[1,2]',
repliesLastID: 1,
replies: '[]',
createdAt: 2022-04-08T06:29:22.227Z,
updatedAt: 2022-04-09T04:27:43.171Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 3,
text: 'Welcome to Cheese.social!',
creator: 0,
created: 2022-04-09T01:57:51.059Z,
likes: '[1,2]',
repliesLastID: 3,
replies: `[{"id":1,"author":1,"text":"Yeah ik right cheese","likes":[1,2]},{"id":2,"author":1,"text":"cheese; SELECT * FROM Users;","likes":[]},{"id":3,"author":2,"text":"Yo dude! Cheese.social is greeeeeeeeeeeeeeeeeat. btw bro don't try sneaky sqli pleasesae","likes":[2]}]`,
createdAt: 2022-04-09T01:57:51.061Z,
updatedAt: 2022-04-09T04:28:41.572Z
},
_previousDataValues: {
id: 3,
text: 'Welcome to Cheese.social!',
creator: 0,
created: 2022-04-09T01:57:51.059Z,
likes: '[1,2]',
repliesLastID: 3,
replies: `[{"id":1,"author":1,"text":"Yeah ik right cheese","likes":[1,2]},{"id":2,"author":1,"text":"cheese; SELECT * FROM Users;","likes":[]},{"id":3,"author":2,"text":"Yo dude! Cheese.social is greeeeeeeeeeeeeeeeeat. btw bro don't try sneaky sqli pleasesae","likes":[2]}]`,
createdAt: 2022-04-09T01:57:51.061Z,
updatedAt: 2022-04-09T04:28:41.572Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 4,
text: 'Cheese, bro!',
creator: 2,
created: 2022-04-09T04:23:42.014Z,
likes: '[2]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-09T04:23:42.014Z,
updatedAt: 2022-04-09T04:28:49.259Z
},
_previousDataValues: {
id: 4,
text: 'Cheese, bro!',
creator: 2,
created: 2022-04-09T04:23:42.014Z,
likes: '[2]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-09T04:23:42.014Z,
updatedAt: 2022-04-09T04:28:49.259Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 5,
text: 'Cheese is great! You should totally eat it.n' +
"Btw, I'm testing https://example.com/#LINKS",
creator: 1,
created: 2022-04-10T09:56:15.243Z,
likes: '[]',
repliesLastID: 3,
replies: `[{"id":1,"author":1,"text":"Links didn't work correctly with cheese.social. They may return in a future update.","likes":[1]},{"id":2,"author":4,"text":"cheese the frick out ofh ere","likes":[]}]`,
createdAt: 2022-04-10T09:56:15.244Z,
updatedAt: 2022-04-11T02:27:12.827Z
},
_previousDataValues: {
id: 5,
text: 'Cheese is great! You should totally eat it.n' +
"Btw, I'm testing https://example.com/#LINKS",
creator: 1,
created: 2022-04-10T09:56:15.243Z,
likes: '[]',
repliesLastID: 3,
replies: `[{"id":1,"author":1,"text":"Links didn't work correctly with cheese.social. They may return in a future update.","likes":[1]},{"id":2,"author":4,"text":"cheese the frick out ofh ere","likes":[]}]`,
createdAt: 2022-04-10T09:56:15.244Z,
updatedAt: 2022-04-11T02:27:12.827Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 6,
text: 'I love me some cheese',
creator: 3,
created: 2022-04-11T01:36:09.758Z,
likes: '[1,3]',
repliesLastID: 2,
replies: '[{"id":1,"author":3,"text":" ikr I love cheese <3","likes":[1]},{"id":2,"author":1,"text":"Yeah cheese is amazing","likes":[1]}]',
createdAt: 2022-04-11T01:36:09.758Z,
updatedAt: 2022-04-11T02:21:21.753Z
},
_previousDataValues: {
id: 6,
text: 'I love me some cheese',
creator: 3,
created: 2022-04-11T01:36:09.758Z,
likes: '[1,3]',
repliesLastID: 2,
replies: '[{"id":1,"author":3,"text":" ikr I love cheese <3","likes":[1]},{"id":2,"author":1,"text":"Yeah cheese is amazing","likes":[1]}]',
createdAt: 2022-04-11T01:36:09.758Z,
updatedAt: 2022-04-11T02:21:21.753Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 7,
text: 'i cheesed ur mother',
creator: 4,
created: 2022-04-11T01:38:23.013Z,
likes: '[4]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T01:38:23.013Z,
updatedAt: 2022-04-11T02:29:07.661Z
},
_previousDataValues: {
id: 7,
text: 'i cheesed ur mother',
creator: 4,
created: 2022-04-11T01:38:23.013Z,
likes: '[4]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T01:38:23.013Z,
updatedAt: 2022-04-11T02:29:07.661Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 8,
text: 'stilton or camembert cheese?',
creator: 5,
created: 2022-04-11T02:26:59.488Z,
likes: '[5,1]',
repliesLastID: 1,
replies: `[{"id":1,"author":1,"text":"I say Camembert, it's a good cheese.","likes":[]}]`,
createdAt: 2022-04-11T02:26:59.489Z,
updatedAt: 2022-04-11T02:28:58.565Z
},
_previousDataValues: {
id: 8,
text: 'stilton or camembert cheese?',
creator: 5,
created: 2022-04-11T02:26:59.488Z,
likes: '[5,1]',
repliesLastID: 1,
replies: `[{"id":1,"author":1,"text":"I say Camembert, it's a good cheese.","likes":[]}]`,
createdAt: 2022-04-11T02:26:59.489Z,
updatedAt: 2022-04-11T02:28:58.565Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 9,
text: 'I like cheese',
creator: 6,
created: 2022-04-11T02:30:29.244Z,
likes: '[6]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T02:30:29.245Z,
updatedAt: 2022-04-11T02:31:33.682Z
},
_previousDataValues: {
id: 9,
text: 'I like cheese',
creator: 6,
created: 2022-04-11T02:30:29.244Z,
likes: '[6]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T02:30:29.245Z,
updatedAt: 2022-04-11T02:31:33.682Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 10,
text: 'Cheese and pasta!!',
creator: 6,
created: 2022-04-11T02:32:39.524Z,
likes: '[6,1]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T02:32:39.525Z,
updatedAt: 2022-04-11T02:33:23.727Z
},
_previousDataValues: {
id: 10,
text: 'Cheese and pasta!!',
creator: 6,
created: 2022-04-11T02:32:39.524Z,
likes: '[6,1]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T02:32:39.525Z,
updatedAt: 2022-04-11T02:33:23.727Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 11,
text: 'Cheese is yum uwu',
creator: 7,
created: 2022-04-11T02:40:40.170Z,
likes: '[]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T02:40:40.170Z,
updatedAt: 2022-04-11T02:48:26.315Z
},
_previousDataValues: {
id: 11,
text: 'Cheese is yum uwu',
creator: 7,
created: 2022-04-11T02:40:40.170Z,
likes: '[]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T02:40:40.170Z,
updatedAt: 2022-04-11T02:48:26.315Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Post {
dataValues: {
id: 12,
text: 'Cheese is great! You should totally eat it.n<marquee>Cheese</marquee>',
creator: 7,
created: 2022-04-11T02:44:03.630Z,
likes: '[]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T02:44:03.631Z,
updatedAt: 2022-04-11T02:44:03.631Z
},
_previousDataValues: {
id: 12,
text: 'Cheese is great! You should totally eat it.n<marquee>Cheese</marquee>',
creator: 7,
created: 2022-04-11T02:44:03.630Z,
likes: '[]',
repliesLastID: 0,
replies: '[]',
createdAt: 2022-04-11T02:44:03.631Z,
updatedAt: 2022-04-11T02:44:03.631Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
}
]