Я пытаюсь сделать простой запрос в firestore, включая текстовый поиск. Для разбивки на страницы я использую поле для сортировки по дате. Если я помещаю два ordeby (), один в поле ввода, он перестает выдавать ошибку, но ничего не приносит. И если я оставлю только ordeBy () для createAt, он даст это e
if (category) {
console.log('categoria')
query = query.where('category', '==', category)
}
if (textSearch) {
console.log('texto = ' + textSearch)
query = query.where('introduction', '>=', textSearch)
.where('introduction', '<=', `${textSearch}\uf8ff`)
}
if (author) {
console.log('autor')
query = query.where('author', '==', author)
}
if (!last) {
console.log('Nao tem last')
const myStories = await query.orderBy('createdAt', 'desc').limit(limit).get()
console.log(myStories.docs.length)
last = myStories.docs.length > 0 ? myStories.docs[0].data().createdAt : ''
}
Erro:
index.cjs.js?e89a:160 Uncaught (in promise) FirebaseError: Invalid query. You have a where filter with an inequality (<, <=, >, or >=) on field 'introduction' and so you must also use 'introduction' as your first Query.orderBy(), but your first Query.orderBy() is on field 'createdAt' instead.
at new n (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:160:23)
at t.kE (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:14446:34)
at t.SE (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:14443:32)
at t.orderBy (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:14242:21)
at _callee4$ (webpack-internal:///./src/store/modules/stories/actions.js:138:26)
at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:45:40)
at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:274:22)
at Generator.prototype.<computed> [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:97:21)
at asyncGeneratorStep (webpack-internal:///./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:12:24)
at _next (webpack-internal:///./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:34:9)
n @ index.cjs.js?e89a:160
t.kE @ index.cjs.js?e89a:14446
t.SE @ index.cjs.js?e89a:14443
t.orderBy @ index.cjs.js?e89a:14242
_callee4$ @ actions.js?f4dd:28
tryCatch @ runtime.js?96cf:45
invoke @ runtime.js?96cf:274
prototype.<computed> @ runtime.js?96cf:97
asyncGeneratorStep @ asyncToGenerator.js?1da1:3
_next @ asyncToGenerator.js?1da1:25
Promise.then (async)
dispatch @ vuex.esm.js?2f62:459
boundDispatch @ vuex.esm.js?2f62:347
local.dispatch @ vuex.esm.js?2f62:706
mappedAction @ vuex.esm.js?2f62:991
saveFilter @ AppBar.vue?9c7c:171
click @ AppBar.vue?8369:164
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1854
invoker @ vue.runtime.esm.js?2b0e:2179
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1854
Vue.$emit @ vue.runtime.esm.js?2b0e:3888
Vue.<computed> @ backend.js:1793
click @ VBtn.ts?0eff:156
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1854
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917