How to retrieve value of a key without having to write the entire key? #16334
-
Let's say I have a key which stores information about some children who study at a school. The value is going to be the name of the child The key looks like: Example My question is: How can I retrieve the name of ALL children who are studying in the ColomboSchool, whose roll number is 22? Let's just assume I do not know or I do not want to enter the class/grade and I want to see all the children that study at ColomboSchool & have roll number 22. Is there any pre-built command in etcdctl to make this happen? Or how can I find the names of all students studying in ColomboSchool without mentioning their class/grade or rollNumber? I did use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @Anand11Yash - Thanks for your question. etcd as a key value store doesn't have complex query capabilities like a traditional relational database, so you need to structure your keys in a way that makes querying feasible. The approach you are taking with etcdctl get --prefix "/schools/ColomboSchool" | grep "22" |
Beta Was this translation helpful? Give feedback.
Hey @Anand11Yash - Thanks for your question. etcd as a key value store doesn't have complex query capabilities like a traditional relational database, so you need to structure your keys in a way that makes querying feasible.
The approach you are taking with
etcdctl get --prefix
and then further filter with additional tools likegrep
makes sense to me. Perhaps just extend your prefix to also includeColomboSchool
so one less grep iteration is required.