My indexes:
{ fields: [ { _id: 'asc' } ] }
{ fields:
[ { origin: 'asc' },
{ seasonId: 'asc' },
{ leaderboardTag: 'asc' },
{ riftLevel: 'asc' },
{ riftTime: 'asc' } ] }
{ fields:
[ { origin: 'asc' },
{ seasonId: 'asc' },
{ leaderboardTag: 'asc' } ] }
{ fields:
[ { origin: 'asc' },
{ seasonId: 'asc' },
{ hardcore: 'asc' },
{ heroClass: 'asc' } ] }
{ fields:
[ { riftLevel: 'asc' },
{ riftTime: 'asc' },
{ origin: 'asc' },
{ seasonId: 'asc' },
{ hardcore: 'asc' },
{ heroClass: 'asc' } ] }
{ fields:
[ { riftLevel: 'asc' },
{ riftTime: 'asc' },
{ origin: 'asc' },
{ seasonId: 'asc' },
{ leaderboardTag: 'asc' } ] }
{ fields:
[ { origin: 'asc' },
{ seasonId: 'asc' },
{ hardcore: 'asc' },
{ heroClass: 'asc' },
{ riftLevel: 'asc' },
{ riftTime: 'asc' } ] }
My find query:
try {
const selector = {
riftLevel: { $ne: null },
riftTime: { $ne: null },
origin,
seasonId,
leaderboardTag,
}
return (await Leaderboard.db.find({
selector,
sort: [{ riftLevel: 'asc'}, {riftTime: 'asc'}, { origin: 'asc' }, { seasonId: 'asc' }, { leaderboardTag: 'asc' }],
})).docs;
} catch (error) {
logger.error(error);
throw error;
}
The error:
Error: Cannot sort on field(s) "riftLevel,riftTime,origin,seasonId,leaderboardTag" when using the default index
What am I doing wrong? Clearly the index is there and the fields match, cant figure it out.
Please help, otherwise i will have to change database.
I seem to recall, that all fields you want to sort on, also need to be in the selector, which you have, but you don't have a condition on the origin, seasonId, nor leaderboardTag in the selector?
no condition but values, e.g. origin: 'eu'. (just like the api guide does: https://github.com/nolanlawson/pouchdb-find)
do I need conditions?
try {
const selector = {
riftLevel: { $ne: null },
riftTime: { $ne: null },
origin,
seasonId,
leaderboardTag,
}
return (await Leaderboard.db.find({
selector,
sort: [
{ riftLevel: 'asc'},
{riftTime: 'asc'},
{ origin: 'asc' },
{ seasonId: 'asc' },
{ leaderboardTag: 'asc' }
],
})).docs;
} catch (error) {
logger.error(error);
throw error;
}
In your selector above, you just say origin, not origin: myOrigin or origin: 'eu' ? Or am I missing something?
origin is shorthand for origin: origin :)
Read more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer
"
With ECMAScript 2015, there is a shorter notation available to achieve the same:
var a = 'foo',
b = 42,
c = {};
// Shorthand property names (ES2015)
var o = {a, b, c};
// In other words,
console.log((o.a === {a}.a)); // true
"
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.