Reputation:
I wish to use Cloudant Query to get all the documents wuth the specified field is matched with a string (similar to SQL "LIKE") but I just can't figure out how to do it.
I realize I can use Search Index for this purpose but I would love to know the solution using Cloudant Query.
Upvotes: 1
Views: 3579
Reputation: 3737
To search multiple fields, you can use Cloudant Query's combination operators, for example:
{
"selector": {
"$or": [
{ "person": { "$regex": "Rob" }},
{ "pet": { "$regex": "Rob" }}
]
},
"fields": [
"person",
"pet"
]
}
For more info, see https://docs.cloudant.com/cloudant_query.html#combination-operators
Upvotes: 1
Reputation: 706
You could use the $regex
operator, which allows you to use a regular expression pattern. For example,
{
"selector": {
"person": {
"$regex": "Rob"
}
},
"fields": [
"person"
]
}
Additional info:
https://docs.cloudant.com/cloudant_query.html#condition-operators
Upvotes: 1