Make your data beautiful again.
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 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}]}
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}
Replaces the property with the current date and time
{currentDate: $date}
Extracts the month from the property value indicated
{currentMonth: {$month: somevalue/expression}}
extracts the day of the month from the property value indicated
{currentDay: {$dayOfMonth: somevalue/expression}}
Extracts the year from the property value indicated:
{currentYear: {$year: somevalue/expression}}
Multiply the values in the supplied list
{multipliedValues: {$multiply: [1,2]}}
Divide the values in the supplied list.
{dividedValues: {$divide: [1,2,3]}}
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}}}
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}}}
Test to see if the values supplied are the equal, doubles will be compared to integers by converting the integer to a double first. Strings will be compared case sensitively.
{result: {SomeValue: {$eq: "1"}}}
Test to see if the values supplied are strings and the same ignoring case
Test to see if the the values are contained within a string.
{result: {SomeValue: {$contains: ["hello", "ell"]}}}
Test to see if the values supplied are started by a value
{result: {SomeValue: {$startsWith: "1"}}}
Test to see if the values supplied are ended by the value
{result: {SomeValue: {$endsWith: "1"}}}
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: {$ne: 1}}}
returns the first value from a list
{result: {$popFirst: alist}}
returns the last value from a list
{result: {$popLast: alist}}
returns the uppercase value
{result: {$upper: "aaaa"}}
returns the lowercase value
{result: {$lower: "AAA"}}
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.*")
Allows you to query a collection for documents that fit within the specified geo shape, such as polygon, line, linestring, center, point etc.
db.collection.find({location: {$geoWithin: { type: "Point", coordinates: [ 30, 5 ] } }} )
More information found in the geospatial section.
© 2021 monsterDB. Built using WordPress and Mesmerize Theme.