MonsterDB – Operators

operators and expressions

Operators

Operators allow you to specify the behaviour of the system, like using logical statements (or, and) expressions are multiple function type statements built up in a document structure.

$or

Or operator allows you to specify multiple conditions that will be evaluated

CLI Usage: db.collection.find({"$or": [{"LastName":"Haynes"}, {"LastName":"Smith"}]}]

API Usage: cursor = collection.find(document)

where document is equivalent to {"$or": [{"LastName":"Haynes"}, {"LastName":"Smith}]}

 

$and

Or operator allows you to specify multiple conditions that will be evaluated
CLI Usage: db.collection.find({"$and": [{"FirstName":"Bob"}, {"LastName":"Smith"}]}]
API Usage: cursor = collection.find(document) where document is equivalent to
{"$and": [{"FirstName":"Bob"}, {"LastName":"Smith}]}
Please be aware that the above statement will not evaluate to the same as a simple query in one document: {“FirstName”:”Bob”, “LastName”:”Smith} 

$date

Replaces the property with the current date and time
{currentDate: $date}

$month

Extracts the month from the property value indicated
{currentMonth: {$month: somevalue/expression}}

$dayOfMonth

extracts the day of the month from the property value indicated
{currentDay: {$dayOfMonth: somevalue/expression}}

$year

Extracts the year from the property value indicated:
{currentYear: {$year: somevalue/expression}}

$multiply

Multiply the values in the supplied list
{multipliedValues: {$multiply: [1,2]}}

$divide

Divide the values in the supplied list.
{dividedValues: {$divide: [1,2,3]}}

$gt

Test to see if the values supplied (numeric only) are the greater, doubles will be compared to integers by converting the integer to a double first.

{result: {SomeValue: {$gt: 1}}}

$lt

Test to see if the values supplied (numeric only) are the lesser than, doubles will be compared to integers by converting the integer to a double first.
{result: {SomeValue: {$gt: 1}}}

$eq

Test to see if the values supplied (numeric only) are the equal, doubles will be compared to integers by converting the integer to a double first.
{result: {SomeValue: {$eq: 1}}}

Regular Expressions

Regular expression can be used in filters and find/$match operators. Regular expressions are evaluated using java, so will conform to the rules:
A regular expression, or regex, is a sequence of characters that specifies a pattern which can be searched for in a text. A regex defines a set of strings, usually united for a given purpose. Suppose you need a way to formalize and refer to all the strings that make up the format of an email address. Since there are a near infinite number of possible email addresses, it’d be hard to enumerate them all. However, as we know an email address has a specific structure, and we can encode that using the regex syntax.
A regex processor translates a regular expression into an internal representation which can be executed and matched against the text being searched. It will tell you whether a string is in the set of strings defined by a pattern or find a substring that belongs in that set.

Example in CLI
{"pattern":"Rob.*", flags":0}
Using java.util.regex.Pattern in the API:
Pattern.compile("Rob.*")