The USPTO Registered Logo Badge of the Medical Marijuana Initiative of North America - International Limited, an Arizona Benefit Corporation to the left of Mt Hood sunlit from the northwest in June followed by the proprietary MMINAIL octocopter delivery bot.

MongoDB Commands and Functions


Welcome! This is the Version Number Page of the Carbon Free Footprint project.

The code snippets for this article have been extracted ( and, spruced up a little bit ) from the Little MongoDB eBook by Karl Seguin

Getting Started

To install the Mongo DB database software in Mac OSX using MacPorts visit this repo on GitHub ...

How To Install Mongo DB On Mac OSX With MacPorts via GitHub

Because the Mongo Server (MS) shell is written in Javascript ... ( the parenthesis ) are very important!

Semi-colons are shown here and there throughout the code samples to illustrate a line ending. But, are not needed in the Javascript shell of MongoDB to execute a command line.

Further, the lines of code shown within the code blocks are encased within a Liquid wrapper.

To further faciliate reading the text of the code on a MacBook Pro ... breaks in the code have been set based on a laptop screen.

What follows, are some important MongoDB Shell commands and functions for the fledgling reader to master.

It is debatable whether or not we should render this repo for smaller screens ( or, conversely larger screens ) separately.

When viewing this repo on a smart phone, for example, the responsiveness of the slide to lower dimensions begs reconfiguration.

This repo 'works' well when viewing from a MacBook Pro laptop screen ... But, the author is open to tweaking the html and css to render effectively for other screens.

You know the drill ... Fork it, and send me a pull request!

As you can see when digging into this repo, the GitHub pages engine will accept Bootstrap 3.0 ( and, Angular 2 ) enhancements.

But, connecting a MongoDB document database and then constructing forms to fill it ...?

No, there is no 'server-side' coding allowed via the GitHub pages engine ... at this time.

More to come ... All client based.


The Fun Begins Here

Here, a block of code for the MongoDB Javascript shell may be displayed and wordwrapped in real time via GitHub Pages when enclosed in a proper Liquid wrapper.

Each subheading that follows represents a MongoDB command or an important function with a little bit of explanation tossed in as a Javascript comment to whet the whistle of the database specialist.


Mongo Chevron

Intro to the Chevron ...

Once you have successfully installed MongoDB on your machine you may open up a terminal window and type 'mongo'. The command 'mongo' will connect a shell to your running server and the 'chevron' will appear.

1
2
3
// where the Mongo Server (MS) accepts commands
// a.k.a the 'chevron'
>;
For Example ( Por Ejemplo ) ...
1
2
// Enter your command here at the 'chevron' prompt
>;

Mongo Version

Intro to the 'version()' function ...

Where 'db' is the wake-up command to the (MS) to provide the current 'version' of the Mongo Server (MS).

1
2
3
4
5
6
7
8
//Type the following function
db.version();
//The (MS) returns the version number
//of your MongoDB install
3.2.11
//The 'chevron' promptly returns ready
//for your next command ( or, function )
>;

Mongo Help

Intro to the 'help()' function ...

Where 'db' is the wake-up command to the Mongo Server (MS) to provide general 'help'.

1
2
3
//Type the following function
db.help();
//The (MS) returns a list of general help items
For Example ( Por Ejemplo ) ...

(MS) will also provide detailed 'specific' help, too ... Whenever a collection is specified within the 'help' function.

Where 'frame' is the name of a collection of documents within the current working database.

1
2
3
//Type the following function 
db.frame.help();
//The (MS) returns a list of specific help items

Mongo Use

Intro to the MongoDB 'use' command ...

How To Declare and Change the Working Database ...

Where the command 'use' asks the (MS) to switch to the database named 'cls'... Even if the database has not yet been created!

1
2
3
4
5
6
//Type the following function 
use cls;
//The (MS) responds
>switched to db cls
// then the 'chevron' prompt returns
>;

The response from the (MS) whereby the Mongo Server (MS) basically says 'the switch is in effect' to the database 'cls' ... Stays in effect until changed once again by the 'use' command.

The opening default of the (MS) is towards the built-in 'test' database.

So, the first thing a user performs after typing the command to start the mongo shell ( 'mongo') is to type the command 'use' in order to orient the (MS) towards the correct base of data.

For Example ( Por Ejemplo ) ...
1
2
3
4
5
6
7
//Start the shell
mongo;
//Switch to the working database
use learn;
>switched to db learn
// then the 'chevron' prompt returns
>;

Mongo getCollectionNames() function

Intro to the MongoDB 'getCollectionNames()' function ...

Initially, when performing this 'getCollectionNames()' function on a database void of any 'collection', the prompt returns an empty array '[  ]', as follows:

1
2
3
4
5
6
7
8
9
//where the result is an empty array of collections
//the function returns the symbol '[ ]'
//Type the following function 
db.getCollectionNames();
//The (MS) responds
>[ ];
//Then the 'chevron' prompt returns
//for the entering of the next command
>;
For Example ( Por Ejemplo ) ...

Where a database named 'learn' holds a single collection named 'unicorns'.

1
2
3
4
5
6
//Type the following function
db.getCollectionNames();
//the function returns an array of one
[ "unicorns" ]
//Then the 'chevron' prompt revisits the terminal
>;

Mongo Insert

Intro to the MongoDB 'insert()' function ...

How To Insert a Single Document Into the 'frame' Collection of the Working Database?

For Example ( Por Ejemplo ) ...

Where the result is a single inserted document into the 'frame' collection ...

Where one or more 'key: value' sets of 'fields' within a single document are to be declared with the insert function.

1
2
3
4
5
6
7
8
9
10
11
12
13
// When hitting the carriage return after typing ...
db.frame.insert({
	name: 'Aurora',
	gender: 'f',
	weight: 450
});
// the (MS) returns the following result
WriteResult({ "nInserted" : 1 })
//The result is a single document
//has been added to the collection 'frame'
>;
//After the (MS) acknowledges the insert ...
//the 'chevron' prompt returns

Mongo getCollectionNames() revisited

Revisiting the MongoDB 'getCollectionNames()' function ...

After inserting the single document into the 'frame' collection ...

When we pull the function 'getCollectionNames()' again from the arsenal of functions available in MongoDB we get an acknowledgement from the (MS) that a collection named 'frame' has also been created where previously there was an 'empty array' returned, as follows:

1
2
3
4
5
6
7
//Type the following function
db.getCollectionNames()
>[ "frame" ]
//where a collection named 'frame'
//is now resident in the working database
//Then the 'chevron' prompt returns
>;

In effect, the collection was declared first, and then a document was inserted secondly into the working database. Consequently, all of the fields ( key - value pairs ) of the now inserted document are house'd within the collection 'frame' of the working database.


Simple Array

How To Insert a Simple Array Into the 'frame' Collection ...

A simple array is considered to be its own document, as well.

Remember, Simple Arrays appear within a [ set of brackets ] in Mongo.

For Example ( Por Ejemplo ) ...
1
2
3
4
5
6
7
8
9
10
11
// If successful upon tapping the 'enter' key ...
db.frame.insert({"fruits" : [
"apple",
"pear",
"orange",
"banana"]
});
// the (MS) returns the following result
WriteResult({ "nInserted" : 1 })
// And, the 'chevron' prompt revisits the terminal
>;

Here, try another array ...

For Example ( Por Ejemplo ) ...
1
2
3
4
5
6
7
8
9
10
11
12
// If successful upon tapping the 'enter' key ...
db.frame.insert({"autos" : [
"chrysler",
"bmw",
"ford",
"general motors",
"volkswagen"]
});
// the (MS) returns the following result
WriteResult({ "nInserted" : 1 })
// And, the 'chevron' prompt revisits the terminal
>;

Embedded Document

How To Insert an Embedded Document Into the 'frame' Collection ...

An Embedded Document holds the key - value pairs of another document.

For Example ( Por Ejemplo ) ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// If, however, the insert is not successful ...
db.frame.insert({"home" : "ejs26aa01a",
"address" : {
	"owner : "Edward John Smith",
	"phone" : "206-000-0000",
	"correo" : "1423",
	"street" : "Jerry",
	"type" : "Rd",
	"compass" : null,
	"city" : "Seattle",
	"state" : "WA",
	"zip" :  "98109-5210"}
});
//the (MS) will return an error message
//similar to the following ...
SyntaxError: missing :
after property id @(shell):3:9

Here, the operator failed to close "quotes" in line 3, at character 9

1
2
3
4
// Should be "owner" ... now, you're cook'n!
WriteResult({ "nInserted" : 1 })
// And, the 'chevron' prompt revisits the terminal
>;

Try another Embedded Document ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// This one looks accurate ...
db.frame.insert({"person" : "20nov16ejs26aa01a",
"name" : {
	"last" : "Smith",
	"first" : "Edward",
	"mid" : "John",
	"suffix" : null,
	"dob" : "010177",
	"bmi" : 30.05,
	"email" : "jsmiwa@me.com",
	"entity" : "206WA98109a1a001",
	"home" : "ejs26aa01a"}
});
// And it is!
WriteResult({ "nInserted" : 1 })
// the 'chevron' prompt revisits the terminal
>;

Notice how the accurate 'person' document holds a 'key - value' pair that corresponds to the 'entity' document below as well as the 'home' document above.

A Dun and Bradstreet assigned business number can substitute for the 'entity' value, and a county parcel number can substitute for the value of the 'home' key.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// This one looks accurate, too ...
db.frame.insert({"entity" : "206WA98109a1a001",
"address" : {
	name : Amazon Legal Dept,
	"phone" : "206-266-4064",
	"correo" : "410",
	"street" : "Terry",
	"type" : "Avenue",
	"compass" : "North",
	"city" : "Seattle",
	"state" : "WA",
	"zip" :  "98109-5210"
	credit : a1a}
});
// And it is!
WriteResult({ "nInserted" : 1 })
// the 'chevron' prompt revisits the terminal
>;

Mongo Find

Intro to the MongoDB 'find()' function ...

How to find a document in a Mongo collection using dot notation via the 'db.collection.find()' function.

Set up your query in Terminal where 'frame' is the name of a collection in the working database.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Type the following function
db.frame.find({'address.street' : 'Jerry'})
//The (MS) returns the entire document ...
//To the Terminal window
//Including the identifying ...
//auto-generated 'hash' for the document
{ "_id" : ObjectId("5839ef0545cc496e4f431110"),
"home" : "ejs26aa01a",
"address" : {
	"phone" : "206-000-0000",
	"correo" : "1423",
	"street" : "Jerry",
	"type" : "Rd",
	"compass" : null,
	"city" : "Seattle",
	"state" : "WA",
	"zip" : "98109-5210",
	"owner" : "Edward John Smith"
	}
}
// And, the 'chevron' now appears
>;

Another way to perform this type of search ( find ) is to query the collection using the Mongo Compass rather than via the Terminal.

The Mongo compass has an input line front and center on the 'Schema' tab where simply the query sans the function can be entered, as follows:

Set up your query via the 'Schema' tab of Mongo compass where 'frame' is the name of a collection in the working database.

1
2
//Type the following query in Mongo compass
{"address.street" : "Jerry"}

Notice the Mongo compass requires "double quotes" when entering the key - value pair whereas the Terminal function will accept 'single quotes'.

One of the really cool features of the Mongo compass is the ability to pick and choose the 'fields' you wish to build your query upon by simply clicking the available elements shown.

For Example ( Por Ejemplo ) ...

Let's say you wish to query a collection within the working database for the value 'banana'...

Set up your query via the 'Schema' tab of Mongo compass where 'frame' is the name of a collection in the working database.

1
2
//Type the following query in Mongo compass
{"fruits":"banana"}

Or, for the value 'btw' ...

Remember, the Mongo compass requires "double quotes" when entering the key - value pair.

Set up your query via the 'Schema' tab of Mongo compass where 'frame' is the name of a collection in the working database.

1
2
//Type the following query in Mongo compass
{"autos":"bmw"}

Now, by clicking on the 'Documents' tab in Mongo compass ...

The document housing the inquiry value appears ( similar to the above Terminal result ), as follows:

1
2
3
4
5
6
7
8
// Query returned 1 document.
_id:ObjectID('5839eae645cc496e4f43110d')
autos:Array[5]
0:"chrysler"
1:"bmw"
2:"ford"
3:"general motors"
4:"volkswagen"

Conclusion. Other than the continuing caveat to render your query with "double quotes" ...

The Terminal proves cumbersome when compared to the ability to query effectively through Mongo compass.


Mongo Indexes

Intro to the MongoDB 'getIndexes()' function ...

When we pull the function 'getIndexes()' from the arsenal of functions available in MongoDB ...

Where 'frame' is a collection in the working database.

1
2
//Type the following function
db.frame.getIndexes();

Mongo Remove

Intro to the MongoDB 'remove() function ...

To wipe a collection clean ...

Invoke the simplest of JSON objects ( which is the Empty Object ) denoted by a vacant set of curly braces '{  }'.

Here, the Empty Object '{  }' matches the term 'All Documents'.

To remove all of the documents currently stored in the collection 'frame' invoke the following ...

1
2
//Type the following function
db.frame.remove({ })

Mongo Export

Intro to the MongoDB 'mongoexport' command ...

Where an 'export' data command to a (.json) or a (.csv) file may be excuted.

1
2
//Type the following helper command
mongoexport;

JSON is the default format used by MongoDB when exporting data ( fields ) from a collection within a database.

A data output in JSON format can be rendered by the (MS), as follows:

Where 'yourdata' is the name of a MongoDB database, and 'frame' is the name of a collection of documents within your MongoDB database.

1
2
//Type the following helper command
mongoexport --db yourdata --collection frame

MongoDB can also export data ( fields ) into the standard (.csv) format, as well.

Here, the (MS) exports the (.csv) fields of name, weight, and gender from the 'frame' collection within the database named 'yourdata'.

1
2
3
//Type the following helper command
mongoexport --db yourdata --collection frame
--csv --fields name,weight,gender

Mongo Import

Intro to the 'mongoimport' command ...

Where an import data command from a (.json) or a (.csv) file may be excuted.

1
2
//Type the following command
mongoimport;

Mongo Stats

Intro to the 'stats()' function ...

Where 'db' is the wake-up command to the Mongo Server (MS) to provide 'stats'.

1
2
//Type the following function
db.stats();

Mongo Count

Intro to the 'count()' function ...

The (MS) will provide a specific 'count' where 'frame' is the name of a collection of documents within the current working database.

1
2
//Type the following function
db.frame.count();

Mongo Status

Intro to the 'serverStatus()' function ...

Where 'db' is the wake-up command to the (MS) to provide the current 'serverStatus' of the Mongo Server (MS).

1
2
//Type the following function
db.serverStatus();

Mongo Test

More to come ...

1
2
3
4
//Type the following function
>;
//Back to the 'chevron'
>;
For Example ( Por Ejemplo ) ...

More to come ...

1
2
3
4
//Type the following function
>;
//Back to the 'chevron'
>;
.

Supporting Content


Welcome! This is the Supporting Content section for the MMINAIL Central Live Repository.


E Books


With today's explosion of modern devices, some consumers like to read their articles on their Kindles or iPads.

Therefore, a method to convert any page of this website into an 'eBook' is auto-built into the top of the navigation stack as well as in the footer of every page.

Simply click the small dot epub button eBook icon to render the current page as an Overdrive (.epub) or a Kindle (.mobi) for external reading.

Note. The Apple iBooks platform also reads and displays the (.epub) format.


The A's Have It!


In today's complicated world of coding, even the use of the standard hyperlink has come into question.

Therefore, to make it easy for the end-user, this User Interface, or UI will show safe internal links in the bootstrap default color of light dodger blue.

On the other hand, external links, when designated https secure ... Will be shown in the color of forest green.

All other external links designated with standard http will be shown in the color of indian red.


Acronyms


For an acronym to be visually effective when reading a line of text, the acronym must first be declared.

In addition, the acronym must stand out from the body of information.

To accomplish both of these objectives, the authors have selected Ashley Gold, a primary color within the registered logo badge of the Benefit corporation for which to highlight acronyms.

Whenever the end user spies a designated acronym of Ashley Gold color, simply hover over the acronym to reveal the underlying meaning of the acronym letters.


Screen Responsiveness


This page has been tested for mobile responsiveness on a virtual Galaxy S5 smartphone emulator.

The authors have determined the accuracies of the page renderings at both a portrait width of 360px and a landscape width of 640px.

In addition, pages are also tested against an Amazon Kindle Fire HDX 7, 3rd Generation tablet.

On the Kindle tablet, both portrait and landscape renderings appear accurate, as well.

And, on the Amazon Fire phone, using automatic screen rotation, both portrait and landscape renderings appear accurate.


How To Navigate This Website


  • The Navigation to your right is set up to return to this Home page by clicking on the Home icon   south of the divider.

  • To select any of the other topics or subtopics, simply click on the corresponding glyphicon to open up the referenced file.

  • If you get stuck, simply click on the Home icon   below the divider to be hyperlinked back to this Home page.

Got An Idea?


If you have an idea that will spruce this site up even better than it already is, then you know the drill.

Simply go ahead and fork this repo, make your changes, and send me a pull request.


Site Monitoring


Note. The Http Headers of this repo are being monitored by Internet Supervision dot com


25 Mile Rule


The MMINAIL is dedicated to the preservation of the hard-earned rights of Medical patients to grow up to (12) state-legal Medicinal plants.

In a connective cartography of ideas and hyperlinks spanning the entire connectome of the modern Medical Marijuana Initiative ...

The open source authors of this project hope to enlighten the world to the plight of the common medical patient.

Due to a labyrinth of government regulations and costs, today's common medical patient is virtually devoid of healing phyto-cannabinoids and other beneficial terpenes globally for no other reason than his or her current residential address.


Unconstitutional


"When residing 25 miles extant of a state legalized dispensary"

Doesn't that sound a bit strange to you?

Restricting access to medicine ...

Almost Un-constitutional, isn't it?

And, with patients in Arizona paying anywhere from $75 to $90 USD for a (1/8) ounce of medicine ...

Don't you think it is time that we allow ALL patients the right to grow, stash, and cure their own medicines?


Make Contact


We do at the MMINAIL.

If you agree, why don't you donate a little spare cash?

Or, a little of your coding time?

Or, simply contact your favorite Arizona State Senators and Congressional Representatives today!


No Warranty


Disclaimer. The author of this website has made every effort to ensure the accuracy of the information herein.

However, the information contained in this website, and in its pages, is offered to the public without any warranty expressed or implied.

Therefore, the author of this website, and by extension its pages and content cannot be held liable for any damages that may be caused indirectly or directly by the software instructions or tutorials contained in the pages of this website.

For further review, please see the License page of this website and/or the Privacy Policy page of this website to clarify.


Reproduction In Part


Most authors will allow the reproduction of their works in part when the case of brief quotations embodied in critical articles or reviews is addressed.

Therefore, please remember to provide a Link-back to the original author, or to the publisher of the original publication when citing.

Thank you for your consideration.


Fork It


If you are an expert in your field of specialty, then I suggest you fork the working repo of this Website and create a Sub-menu topic of your choosing that may be beneficial to our readers.


Send us a Pull Request.


Our team of coders will review your contribution and get back to you with a "thumbs up" ( or, "thumbs down" ).


Can You Contribute?


As we can now decipher the time spent by our functions at the code block level ...

How much of your coding time are you willing to invest in this project?

As we rely heavily upon contributions from the coding community, your contribution of either cash or code will be greatly appreciated.


Thank you for your contribution.


The Management

The USPTO Registered Logo Badge of the Medical Marijuana Initiative of North America - International Limited, an Arizona Benefit Corporation

Copyright © 2000 - 2017

The Medical Marijuana Initiative of North America Small Registered MMINAIL™ Logo Badge Small Registered MMINAIL™ Logo Badge
- International Limited Small R-Reggae™ Trademark Symbol Logo Badge Small R-Reggae™ Trademark Symbol Logo Badge


To create an iBook/Overdrive (.epub)

or

a Kindle (.mobi) of this page ...

Click the small dot epub button button


This Open Source project is being hosted with Jekyll via GitHub Pages.

All rights reserved. Except where explicity granted.