A
A
Arman2017-06-01 09:08:05
MongoDB
Arman, 2017-06-01 09:08:05

In mongodb, is it possible to sort by part of a field (string)?

The database contains the strings "yyyy-mm-dd hh:ii:ss", you need to sort by part of the string "yyyy-mm-dd". Can I somehow use the substr operator in sorting?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2017-06-01
@Arik

db.collection.find(query).toArray.sort(customSortFunction)

At the same time, it should be taken into account that this is a normal sorting using js tools, so indexes will not be used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question