Find
We use "Query" in the request body to Find the document(s). The query objects consist of a key/value pair of the document, ($or, $like)operators, and (or) a (.)notation.
Querying with an actual "value" condition:
{
"<fieldName>": "<fieldValue>"
}
// example:
{
"CITY": "MUMBAI"
}
Querying with multiple conditions:
Will find the document(s) with the specified condition(s).
{
"<fieldName>": "<fieldValue>",
"<fieldName2>": "<fieldValue2>"
.
.
.
"<fieldName-n>": "<fieldValue-n>"
}
// example:
{
"CITY": "MUMBAI",
"BANK": "ABHYUDAYA COOPERATIVE BANK LIMITED"
}
Using a dot notation:
If you want to query an inner object of the document(s), you can use the dot notation.
{
"<fieldName>.<subFieldName>": "<fieldValue>"
}
// example:
{
"CITY": "MUMBAI",
"BRANCH.NAME": "ABHYUDAYA NAGAR",
"BRANCH.CODE": "ACBLAN01"
}
Operators:
- $like
We can also query the document(s) with partial value using the $like operator.
It will return document(s) that start with the fieldValue given in the fieldName and the specification of $like.
{
"<fieldName>": {
"$like": "<fieldValue>"
},
"<fieldName2.subFieldName2>": {
"$like": "<fieldValue2>"
}
}
// example:
{
"CITY": {"$like": "MU"},
"BRANCH.CODE": {"$like": "ACBL"}
}
NOTE: fieldValue for the $like operator can’t be left empty.
- $or:
$or operator is an array of objects that hold key/value pairs of the document. It will return the document(s) that satisfy any one of the conditions in an array.
Using a dot notation and the $like operator inside an $or operator.
{
"$or": [
{"<fieldName>": "<fieldValue>"},
{"<fieldName2>": {"$like": "<fieldValue2>"},
{"<fieldName3.subFieldName>": "<fieldValue3>"}
]
}
// example:
{
"$or": [
{"CITY": "MUMBAI"},
{"BRANCH.NAME": {"$like": "AH"},
{"BRANCH.CODE": "ACBLAN01"}
]
}
NOTE: $or operator array should be more than 1.
Now let's combine all the queries mentioned above:
{
"BANK": "ABHYUDAYA COOPERATIVE BANK LIMITED",
"$or": [
{"CITY": "MUMBAI"},
{"BRANCH.NAME": {"$like": "AH"},
{"BRANCH.CODE": "ACBLAN01"}
]
}