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 MongoDB 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 Small The Flammarion Logo Badge Small The Flammarion Logo Badge


Welcome! This is the Supporting Content section for the MongoDB Page | Carbon Free Footprint Project page of the MMINAIL.

The Concept Library of the MMINAIL is a static informational website.

As such, a Supporting Content section is placed below each (.html) page in the flow of the default layout to grant the end-user additional pertinent information when navigating this site.


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 <aside> ...

As well as in the <footer> of every page.


Dot ePub

Simply click the following eBook icon = small dot epub button eBook icon to render the current page as an Overdrive (.epub) or a FB Reader (.mobi) .


Apple iBooks

The Apple iBooks platform also reads and displays the (.epub) format, as well.

When navigating the menu at the Navigation <aside> ...

Look for the book icon to download the offered eBook directly to your machine.

Then, simply right-click over the newly downloaded (.epub) and open up the file in the new Book app for Mac devices.


Secure Hyperlinks


The A's Have It!

In today's complicated world of coding, even the use of the standard hyperlink ...

<a href="" title="" target=""></a>

Is placed into question by the standards of newer, more modern browsers such as Google's V8 powered Chrome browser.


Safe Internal Links


Therefore, to make life easy for the end-user ...

The MMINAIL will show safe, internal links in the bootstrap default color of light dodger blue.


Safe External Links


In addition, safe external links ...

When designated https secure ie.) https://.

Will also be shown in the color of light dodger blue.


Standard External Links


All other external links ...

If designated with standard http ie.) http:// ...

Will be shown in the color of indian red.


How To Navigate This Website


At this website ...

We have the <html> hub for the Benefit Corp aka our Concepts Library.

You (Usted), as a current visitor to our Concepts Library, are now at the MongoDB Page | Carbon Free Footprint Project page.


Navigation Aside


In the Navigation <aside> section of this website ...  ...

The end-user will find a Stack of Topics.

Or, for you smartphone users ... the Navigation <aside> section is up! ...  

There, the smartphone user will find the same Stack of Topics for the Concepts Library at MMINAIL.


Stack O Topics


The Navigation <aside> section to your right ... ... If you are viewing this page from the traditional landscape style of your laptop.

Or, the Navigation <aside> section from above ... ... If you are viewing this page from the modern portrait style of your smartphone ...

Both house the same Stack of Topics available for selection at the Concepts Library of the MMINAIL.


Instruction Set


To access one of the Articles or Lessons available for your preferred Topic of Interest ...

  • Simply scroll through the tabs of Topics above, or to the side ...

  • And, click on one that you may have an interest in.

Back Home


Note. At each Topic of Interest, the end-user will find a hyperlink back to the Home page of the Concepts Library.

By clicking on the Home icon   the end-user will be returned to the Home page of the Concepts Library.


Subtopics


When an end-user clicks on a Topic of Interest ...

Either above  ...

Or, over at  ...

The Stack of Topics in the Navigation <aside> section ...

The menu explodes vertically to reveal several subtopical choices.

To select any other Topic of Interest, or any of the many subtitles ...

  • Simply click on the corresponding glyphicon to open up the referenced file.

Unstuck


If you get stuck ...

  • Simply click on the Home icon   to be hyperlinked back to the Home page of the Concepts Library.

Screen Responsiveness


The pages of the Concept Library have been tested for mobile responsiveness.

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


Devices


Testing devices have included selections from the following list of devices ...

  • Amazon Kindle Fire HDX 7, 3rd Generation tablet

  • Virtual Galaxy S5 smartphone emulator

Kindle Tablets

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


Amazon Fire Phones

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


Foreign Language


The foreign language expression ¡Finito! can hold a translation from Spanish-To-English ...

Via the <title> tag.

Simply hover over the word in Spanish to reveal its English equivalent.

For example ...

Hovering over the Spanish phrase ¡Por ejemplo! reveals the English equivalent of "For Example".

Try it!


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 MMINAIL has selected Ashley Gold.


Ashley Gold

Ashley gold is a primary color within the registered Logo Badge of the Benefit corporation.

Whenever the end user spies a designated Acronym of Ashley Gold ...

Simply hover over the Acronym to reveal the underlying meaning embedded in the title element of the <abbr> tag.


Definitions


The <abbr> tag can also be used to house Definitions as well as Acronyms.

As we have seen in the above referenced Ashley Gold definition ...

Whenever the end-user spies a designated Acronym or Definition of Ashley Gold color ...

Simply hover over the Acronym or Definition to reveal the underlying meaning embedded in the title element of the <abbr> tag.


Carriage Return


The carriage return, or ... ➡️

The carriage return is used extensively throughout the working repos of the Concept Library to prevent the overflow of raw code.

By preventing the overflow of raw code when rendering a code block, the view of the end-user avoids the slider effect.

And, by eliminating the slider effect, responsive views using other devices ie.) Kindle Fire HDX will maintain screen boundaries without overflow.


Site Monitoring


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


Reproduction In Part


Most authors will allow for the reproduction of their works in part ...

When the case of brief quotations embodied in critical articles or reviews is addressed.

As long as an appropriate citation is presented concurrent with the review, authors are generally receptive.

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.

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 us a pull request.


Coding Community


If you are an expert in your field of specialty ...

Why not fork our Concept Library and create a new Topic of your choosing, or embellish upon an existing Topic.


Pull Requests


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 Code?


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 code will be greatly appreciated.

Thank you for your effort and participation in our program to code the globe!


Can You Contribute Cash?


If you have enjoyed and benefited from this article ...

Then, why not drop a little change in our digital bucket at the Square Up - Cash Me donation portal.

As we can now spend the equivalent of our grandparents' monthly mortgage payment at our local Sunday football games ...

How much of your spare cash are you willing to invest in this project?


Starving Coders

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

Note. Your donation will help us fund our Starving Coders initiative through our Medcoin™ Crypto Currency Division.


Can You Contribute Ether?


As we have witnessed the exponential growth of Bitcoin (BTC) from 9 cents USD per coin ...

To over $18,000 USD per coin over the past nine (9) years.

Plus, the recent explosion of Ripple (XRP) from less than one-penny to over $2 USD.

How much of your spare Ether ( ETH ) are you willing to invest in this project?

As we rely heavily upon contributions from the coding community, your contribution of ether will be greatly appreciated, as well.


Public Hash

Simply scan the following QR Code to extract our Coinbase public hash address to send Gifts O Wei in support of our Medcoin™ Crypto Currency Project.

QR Code - Coinbase - Bus Card

Note. The easiest and safest way to extract our public `ETH` hash-address is to point your smartphone at the `QR Code` shown and engage the `Sophos Intercept X QR Code Scanner`. From there you will be able to open the link safely via the `Sophos Intercept X Link Checker`.


No Warranty


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

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.


License


The license and privacy policy pages ...

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


Copyright © 2000 - 2021

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