【firestore】Please help me. I can't get where and orderBy to work at the same time. #5417
Unanswered
namachan0219
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Not sure about why using a single "where" isn't working, but for the third option (when you combine everything), you're gonna need a compound index |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone.
I have one question for you.
When I combine where and orderBy in firestore onSnapshot, the data subscription is not executed.
○ onSnapshot & orderBy => subscribe working
✗ onSnapshot & where => subscribe not working
✗ onSnapshot & where & orderBy => subscribe not working
Can someone please tell me how to solve this?
[Data in the firestore collection]
※ createdAt / updateAt → Originally, it has a date.
{
name: "data1",
type: "trends",
updateAt: firestore.FieldValue.serverTimestamp(),
createdAt: firestore.FieldValue.serverTimestamp(),
},
{
name: "data2",
type: "hashtag",
updateAt: firestore.FieldValue.serverTimestamp(),
createdAt: firestore.FieldValue.serverTimestamp(),
},
[My code]
useEffect(() => {
const subscriber = firestore()
.collection("Threads")
.where("type", "==", "trends") or .where("type", "==", "hashtag")
.orderBy("updateAt", "desc")
.limit(10)
.onSnapshot((querySnapshot) => {
... Function to save to state....
});
return () => subscriber();
}, [trigger]);
[Package.json]
{
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "~0.63.4",
"@react-native-firebase/admob": "^11.5.0",
"@react-native-firebase/analytics": "^11.5.0",
"@react-native-firebase/app": "^11.5.0",
"@react-native-firebase/auth": "^11.5.0",
"@react-native-firebase/crashlytics": "^11.5.0",
"@react-native-firebase/database": "^11.5.0",
"@react-native-firebase/firestore": "^11.5.0",
"@react-native-firebase/functions": "^11.5.0",
"@react-native-firebase/perf": "^11.5.0",
"@react-native-firebase/storage": "^11.5.0",
}
Love from Japan to the community.
Beta Was this translation helpful? Give feedback.
All reactions