Slamdata - Mongodb Cheat Sheet Page 2

ADVERTISEMENT

Dates, Times, & Date/Times
Nested Data (Continued)
Block Elements (Continued)
Form Elements (Continued)
Filtering based on timestamp
Filtering by documents in arrays
ATX Headers
A date/time selector that creates a date/time variable called
SELECT
*
FROM
“/prod/purger/events” c
SELECT DISTINCT
*
FROM
“/users” c
# Heading 1
‘start’
WHERE
c.ts >
TIMESTAMP
WHERE
c.profile.allAd-
## Heading 2
start = __ - __ - ____ __ : __ (06-06-2015
‘2015-04-29T15:16:55’
dresses[*].street.number = ‘221B’
### Heading 3
12:00 PM)
Filtering based on time
Paging Result Sets
Indented code blocks (4 spaces)
A required text input eld that creates a string variable
SELECT
*
FROM
“/prod/purger/events” c
SELECT
*
FROM
“/col”
called ‘zip_code’
WHERE
c.ts >
TIME
‘15:16:55’
Limiting results to 20 entries
zip code* = ________ (80302)
SELECT
*
FROM
"/users"
LIMIT
20
Fenced code blocks
Filtering based on date
```
SELECT
*
FROM
“/prod/purger/events” c
Starting results from the 100th entry:
SlamSearch Reference
SELECT
*
FROM
“/col”
WHERE
c.ts >
DATE
‘2015-04-29’
SELECT
*
FROM
"/users"
OFFSET
100
```
SlamSearch is used in various places in SlamData to present
Sorting Result Sets
Extracting a part of a date*
a search-engine-like interface to data in MongoDB.
Paragraphs
SELECT
DATE_PART(‘day’, c.ts)
FROM
Sorting in ascending order by a single eld
Paragraph 1
“prod/purger/events” c
Simple Searches
SELECT
*
FROM
“/users”
ORDER BY
age
ASC
*See Postgres
DATE_PART
function for other options.
Paragraph 2
Search for everything containing the text "foo"
Sorting in mixed order by multiple computed expressions
Aggregation & Grouping
foo
SELECT
*
FROM
“/users”
Block quotes
+foo
Grouping based on single eld*
ORDER BY
age * 2 DESC, ‘Mrs. ‘ +
> This is a block quote.
SELECT DISTINCT
c.age, COUNT(*)
AS
cnt
lastName
ASC
Search for everything not containing the text "foo"
FROM
“/prod/purger/events” c
Lists
-foo
Joining collections
GROUP
BY c.age
1. Item 1
DISTINCT
2. Item 2
*Currently the
is required to avoid duplicates.
Search for anything which is tagged with the `foo` tag
Joining on two di erent collections by a foreign id stored as
#foo
an ObjectId
Inline Elements
Grouping based on multiple elds
SELECT
c1.user, c2.type
SELECT DISTINCT
c.age, c.gender, COUNT(*)
Search for anything
FROM
“/users” c1
Emphasis and strong emphasis
AS
cnt
*
JOIN
“/events” c2 ON c1._id = c2.userId
*Emphasis* and **strong**.
FROM
“/prod/purger/events” c
GROUP
BY c.age, c.gender
Search for anything containing text that starts with "uni"
Joining on two di erent collections by a foreign id stored as
Links
uni*
a string
[SlamData]( )
Grouping based on day
SELECT
c1.user, c2.type
SELECT DISTINCT
DATE_PART(‘day’, c.ts)
AS
Predicate Searches
FROM
“/users” c1
Images
day, COUNT(*) AS cnt
JOIN
“/events” c2
ON
c1._id =
![SlamData Logo]( /lo-
FROM
“/prod/purger/events” c
Search for everything containing a `foo` eld whose value is
OID(c2.userId)
go.png)
GROUP BY
DATE_PART(‘day’, c.ts)
greater than `2`
foo:>2
Conditional expressions
Autolinks
Filtering within a group
< >
SELECT DISTINCT
DATE_PART(‘day’, c.ts)
AS
Use conditionals to test a string eld and generate codes
Search for everything containing a `foo` eld whose value
day, COUNT(*)
AS
cnt
SELECT (CASE
c.gender
falls inside the range 0..2
Inline code
FROM
“/prod/purger/events” c
WHEN
‘male’
THEN
1
foo:0..2
Run this query below: `SELECT * FROM
GROUP BY
DATE_PART(‘day’, c.ts)
WHEN
‘female’
THEN
2
“/col”`
HAVING
c.gender = ‘female’
ELSE
3
Search for everything that does **not** contain a `foo` eld
END)
AS
genderCode
whose value falls inside the range 0..2
Evaluate SQL query and insert results into rendered
Double grouping
FROM
“/users” c
-foo:0..2
Markdown
The outer aggregation function (AVG) operates on the results
There are
!`SELECT
COUNT(*)
FROM
“/col”`
of the inner aggregation (SUM) and
GROUP BY
clause. IE,
Nulls
Search for everything that contains a `foo` eld which
documents inside the collection.
this query returns average population of states.
contains a `bar` eld which contains the text `baz`
SELECT DISTINCT
AVG(SUM(pop))
Choose the rst non-null
foo:bar:baz
Form Elements
FROM
“/zips”
SELECT
COALESCE(c.fullName, c.firstName)
GROUP BY
state
AS
name
Search for everything that contains a `baz` eld matching
A text input eld that creates a string variable called ‘name’
FROM
“/users” c
the SQL `LIKE` pattern `_foo%bar`
name = ________ (Default Name)
Nested Data
baz:~"_foo%bar"
SlamDown Reference
A radio button that creates a string variable called ‘gender’
Extracting deeply nested subdocument
Search for everything that contains anything matching the
gender = () male () female (x) other
SELECT
c.profile.address.street.number
glob pattern `?foo*bar`
SlamDown is a subset of CommonMark (an attempt to
FROM
“/users” c
~?foo*bar
standardize Markdown dialects), with support for two
A bunch of checkboxes that creates a string set variable
extensions: elds and evaluated code (SQL) blocks.
called ‘phones’
Extracting array element in deeply nested subdocument
Search for everything that contains anything greater than `2`
phones = [] Android [x] iPhone [x]
SELECT
c.profile.allAddress[0].street.num-
>2
Block Elements
Blackberry
ber
FROM
“/users” c
Search for anything containing a `foo` eld that starts with
Horizontal rules
A dropdown list that creates a string variable called ‘city’
the text "uni"
Text here
city = {BOS, SFO, NYC} (NYC)
Extracting all array elements simultaneously ( attening)
foo:uni*
SELECT
c.profile.allAddresses[*]
---
A date selector that creates a date variable called ‘start’
FROM
“/users” c
Search for anything containing a metadata attribute called
start = __ - __ - ____ (06-06-2015)
`path` that contains `/foo/bar`
More text here
Extracting all eld values simultaneously ( attening)
@path:/foo/bar
A time selector that creates a time variable called ‘start’
SELECT
c.profile{*}
FROM
“/users” c
start = __ : __ (10:32 PM)

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2