by gnur · 7y ago · 0 comments
Some features that don't scale are very nice to have when you don't have scaling issues. For example, if you add tags to your documents and you want to query on those tags (find all documents containing tag A and B), it's nice that's just a builtin.
I haven't found a single datastore that is as developer friendly that supports that use case, so for now, I'm sticking with mongodb for my pet project.
(if you know of a datastore that has support for this query out of the box, please let me know)
CREATE TABLE documents (name text, tags text[]);
INSERT INTO documents VALUES ('Doc1', '{tag1, tag2}');
INSERT INTO documents VALUES ('Doc2', '{tag2, tag3}');
INSERT INTO documents VALUES ('Doc3', '{tag2, tag3, tag4}');
SELECT * FROM documents WHERE tags @> '{tag1}';
name | tags
------+-------------
Doc1 | {tag1,tag2}
SELECT * FROM documents WHERE tags @> '{tag2}';
name | tags
------+-------------
Doc1 | {tag1,tag2}
Doc2 | {tag2,tag3}
Doc3 | {tag2,tag3,tag4}
SELECT * FROM documents WHERE tags @> '{tag2, tag3}';
name | tags
------+------------------
Doc2 | {tag2,tag3}
Doc3 | {tag2,tag3,tag4}
Postgres certainly isn't perfect, but it's usually a good answer to "how do I store and query data" where you don't have any particular specialist requirements.As I already use MySQL in many projects, I do much the same thing with MySQL's json support.
I believe json is now supported by Sqlite too.
Basically, if you already have an up-to-date relational database, then the chances are you can already use it as a sane document store.
Just saying, so nobody reading the threads thinks they have to go grab some new database if they are already using one!
But also, PostgreSQL supports arrays, so you can have much more native tags as well, and it can be indexed and searched in a more traditional SQL fashion.
I have only used this with Django ORM, but I believe it's pretty straightforward if my memory is correct.
https://firebase.google.com/docs/firestore/query-data/querie...