With a standard RDMS I can find relations by using primary keys and foreign keys. If I want recent comments then I just order by a datetime. If I want all the comments by a user, then I fetch where a comment belongs to that user.
In other words, I can use indexes to filter results. Not just the primary key.
However, with the 开发者_如何学Godocument and key-value NoSQL I can't figure out how I could use them for much more than a text dump. The only thing you can do is fetch the value by an ID.
I need some examples of how you model data in NoSQL when you can no longer use indexes or filters. How do you sort and search data?
If you need secondary indexes like you're describing, then you can't just use any non-relational database. BigTable databases like Cassandra (and probably others) allow for secondary indexes.
If you need to search for things within a Key-Value store based on the values then you'll need to get creative. You could:
1) Create your own keys that point at the original keys and then maintain those pairs on new inserts, updates, and deletes of the original pairs.
2) Just look at every value, brute force, off-line, once a day and save the answer somewhere. Clearly this won't work if you need the new data right away.
Sorting the data will probably need to be done on the application layer or with custom sorted sets if you use technique (1) and Redis.
Which NoSQL database are you using? Berkeley DB, for example, has support for secondary indices.
精彩评论