moleculer-db
moleculer-db copied to clipboard
mongo adapter - can't sort result with text search
Prerequisites
- mongo db with index for textual search
- moleculer-db
- moleculer-db-adapter-mongo
Create a collection with basic data
broker.call('users.create', {
username: "user01",
name: "awesome user",
zip: "54321"
}).then(res => console.log(res));
broker.call('users.create', {
username: "user02",
name: "awesome person",
zip: "12345"
}).then(res => console.log(res));
Current Behavior
Perform a textual search with method 'find' or 'list'
broker.call('users.list', {
search: "awesome",
sort: 'zip'
}).then(res => console.log(res));
Does not sort results at all.
[
{
_id='kB4WHa8EFg3qsKYScXtXPyPP',
username: "user01",
name: "awesome user",
zip: "54321"
},
{
_id='cvWFC4MSWqFBxSYd4mwuBSVw',
username: "user02",
name: "awesome person",
zip: "12345"
}
]
Expected Behavior
We should be able to sort data with a text search.
As stated by the documentation, list should be able to perform a textual search and sort : https://moleculer.services/docs/0.13/moleculer-db.html#find https://moleculer.services/docs/0.13/moleculer-db.html#list
Again, I found out that the base adapter (memory) works. It is related to mongo. As a workaround, I use the 'find' method and sort results myself.
Steps to reproduce
Use the official example as a base : packages/moleculer-db-adapter-mongo/examples/search/index.js
- perform a textual search with method 'list' or 'find' and add parameter 'sort'.
- Results is not sorted.
Context
- moleculer 0.13.9
- moleculer-db 0.8.2
- moleculer-db-adapter-mongo 0.4.5
- moleculer-web 0.8.5
- NodeJS version: 10.3
- Operating System: Alpine Linux (run in a docker container on Ubuntu 18.04)
Issue is a follow up of https://github.com/moleculerjs/moleculer-db/issues/122
same here.
I use moleculer-db with mongodb adapter. sort not working well :(
2019-12-11T02:18:57.521Z 2019-12-10T12:05:47.189Z 2019-12-10T10:21:48.368Z 2019-12-10T10:18:47.660Z 2019-12-10T10:25:25.689Z 2019-12-10T10:22:25.935Z