top | item 43017194

(no title)

javaunsafe2019 | 1 year ago

I also don't get it - it's super easy to write queries with it. Please elaborate...

discuss

order

nonethewiser|1 year ago

stuff like this

SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @> '{"tags": ["qui"]}';

or

SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @? '$.tags[*] ? (@ == "qui")';

which find documents in which the key "tags" contains array element "qui"

https://www.postgresql.org/docs/current/datatype-json.html

Tostino|1 year ago

I had to ask Claude because I've never worked with Mongo, but apparently the equivalent query for MongoDB is:

    db.api.find(
      { "tags": "qui" },
      { 
        "guid": 1, 
        "name": 1,
        "_id": 0
      }
    )