-
Notifications
You must be signed in to change notification settings - Fork 6
Searching The API
Any endpoint can be searched by passing a q
parameter in the URL, i.e. /skills?q=...
. The value of q
should be a MongoDB-style query document. For those that are not familiar with Mongo query documents, a short explanation can be found below.
A "query document" is simply a JSON object that defines fields and values to search by. For example, a request to
https://mhw-db.com/skills?q={"name":"Poison%20Resistance"}
would return a collection containing all skills whose name matched the string "Poison Resistance" exactly.
You can enhance your searches by using operators in your document, a list of which can be found here. For example, a request to https://mhw-db.com/armor?q={"attributes.defense":{"$gt":50}}
would return any armor with a defense that is greater than 50.
You can also search fields that are related or nested in an object. A request to https://mhw-db.com/skills?q={"ranks.level":3}
would return a collection containing all skills that have a rank of 3. A request to https://mhw-db.com/armor?q={"attributes.defense":40}
would return all armor that has exactly 40 defense.
Any field in the API that is an ID of another object or a collection of API objects (for example, the skill
field on Decorations or the skills
field on Charms) can be searched as if it were an object. For example, in order to find any decorations whose skill modifies your ice elemental damage, you could use the following query document on the /decorations
endpoint.
{
"skill.ranks.modifiers.damageIce": {
"$exists": true
}
}
An operator starts with a dollar sign, and allows you to perform more than just equality checks on data.
Name | Description |
---|---|
$and | Joins query clauses with a logical AND. |
$or | Joins query clauses with a logical OR. |
$gt | Matches values that are greater than the specified value. |
$gte | Matches values that are greater than or equal to the specified value. |
$lt | Matches values that are less than the specified value. |
$lte | Matches values that are less than or equal to the specified value. |
$eq | Matches values that are equal to the specified value. |
$neq | Matches values that are not equal to the specified value. |
$in | Matches values that are equal to any of the values in the specified array. |
$nin | Matches values that are not equal to any of the values in the specified array. |
$like | Matches values that match the provided comparison string. |
$nlike | Matches values that do not match the provided comparison string. |
$exists | Matches values that match the given existence check. |
Syntax: {"$and": [{expression1}, {expression2}, ..., {expressionN}]}
The $and
joins query clauses with a logical AND.
{
"$and": [
{
"rank": "high"
},
{
"attributes.defense": 40
}
]
}
The above query, applied to the /armor
endpoint, would find only armor that has a rank
equal to "high, and a defense attribute of 40.
By default, consecutive expressions are joined by an $and
operator, so in most cases it's not necessary to use $and
to join expressions. The above document could be shortened to the following, and would yield the same results.
{
"rank": "high",
"attributes.defense": 40
}
Syntax: {"$or": [{expression1}, {expression2}, ..., {expressionN}]}
The $or
joins query clauses with a logical OR.
{
"$or": [
{
"rank": "high"
},
{
"attributes.defense": 40
}
]
}
The example above would match any entity where rank = "high" OR attributes.defense = 40
.
Syntax: {"field": {"$gt": value}}
The $gt
operator matches values that are greater than the specified value.
{
"attributes.defense": {
"$gt": 40
}
}
The example above would match any entity where attributes.defense > 40
.
Syntax: {"field": {"$gte": value}}
The $gte
operator matches values that are greater than or equal to the specified value.
{
"attributes.defense": {
"$gte": 40
}
}
The example above would match any entity where attributes.defense >= 40
.
Syntax: {"field": {"$lt": value}}
The $lt
operator changes the field comparison to less than.
{
"attributes.defense": {
"$lt": 40
}
}
The example above would match any entity where attributes.defense < 40
.
Syntax: {"field": {"$lte": value}}
The $lte
operator matches values that are less than or equal to the specified value.
{
"attributes.defense": {
"$lte": 40
}
}
The example above would match any entity where attributes.defense <= 40
.
Syntax: {"field": {"$eq": value}}
or {"field": value}
The $eq
operator matches values that are equal to the specified value.
{
"attributes.defense": 40
}
The example above would match any entity where attributes.defense = 40
.
Syntax: {"field": {"$neq": value}}
The $neq
operator is the negated form of $eq
, and matches values that are not equal to the specified value.
{
"attributes.defense": 40
}
The example above would match any entity where attributes.defense != 40
.
Syntax: {"field": {"$in": [value1, value2, ..., valueN]}}
The $in
operator matches values that are equal to any value in the specified array.
{
"rank": {
"$in": [
"high",
"g"
]
}
}
The example above would match any entity where rank IN ("high", "g")
.
Syntax: {"field": {"$nin": [value1, value2, ..., valueN]}}
The $nin
operator is the negated form of $in
, and matches any values that are not equal to any value in the specified array.
{
"rank": {
"$nin": [
"low",
"high"
]
}
}
The example above would match any entity where rank NOT IN ("low", "high")
.
Syntax: {"field": {"$like": value}}
The $like
operator matches any value that matches the specified comparison string.
A comparison string may contain any character allowable in a normal string, but treats the following characters as metacharacters.
Character | Description |
---|---|
% |
Matches anything zero or more times |
_ |
Matches anything once |
To use either character as their literal character and not a metacharacter, simply prefix them with a backslash, like so: \%
or \_
.
{
"name": {
"$like": "Nergal%"
}
}
The example above would match any entity where the name field begins with the string "Nergal" (name LIKE "Nergal%"
).
Syntax: {"field": {"$nlike": value}}
The $nlike
operator is the negated form of $like
, and matches any value that does not match the specified comparison string. Please see the documentation for $like
for an explanation of comparison strings.
{
"name": {
"$nlike": "Nergal%"
}
}
The example above would match any entity where the name field does not begin with "Nergal" (name NOT LIKE "Nergal%"
).
Syntax: {"field": {"$exists": boolean}}
The $exists
operator matches subfield existence. When the value of $exists
is true
, it will match any entity that has the specified field. When it is false, it will match any entity that does not have the specified field.
{
"attributes.slotsRank2": {
"$exists": true
}
}
The example above would match any entity that has the provided field (or, in other words, where attributes.slotsRank2 IS NOT NULL
).
These documents are currently a work in progress. If you notice any mistakes, typos, or if you find any issues in the API itself, please open an issue, or contact me at tyler@lartonoix.com.