Querying multiple values

这一生的挚爱 提交于 2020-07-30 05:54:05

问题


I'm trying to filter by multiple values however I can't seem to get an and clause to work (e.g. filter1 and filter 2 ... etc.):

Show me snapshots where the database name is 'testing'

aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBInstanceIdentifier==`testing`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[
    {
        "SNAPSHOT": "test1",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test2",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test3",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test4",
        "DBNAME": "testing"
    }
]

Show me snapshots named 'test1'

$ aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBSnapshotIdentifier==`test1`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[
    {
        "SNAPSHOT": "test1",
        "DBNAME": "testing"
    },
        {
        "SNAPSHOT": "test1",
        "DBNAME": "testing2"
    }
]

Show me snapshots from the database testing that are named test1

aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBInstanceIdentifier==`testing`][?DBSnapshotIdentifier==`test1`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[]

How can this be achieved?


回答1:


You need to work with the AND expression so something like this will make the trick

$ aws rds describe-db-snapshots --include-shared \
--query 'DBSnapshots[?(DBInstanceIdentifier==`testing` && DBSnapshotIdentifier==`test1`)].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'


来源:https://stackoverflow.com/questions/47163478/querying-multiple-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!