Skip to content

Instantly share code, notes, and snippets.

@shannonbradshaw
shannonbradshaw / SelectionSort.java
Created October 8, 2012 19:19
SelectionSort.java for CSCI 230, Drew University
import structure5.*;
public class SelectionSort
{
public static void main(String args[])
{
ReadStream r = new ReadStream();
int n = r.readInt();
int data[] = new int[n];
int i;
@shannonbradshaw
shannonbradshaw / task-security.rst
Last active July 31, 2016 19:27
Task: Security
  1. Launch a MongoDB Instance
  2. Create a user that can administer users in any database in our MongoDB instance. You may use the following credentials: username: securityofficer password: doughnuts
  3. Restart the MongoDB server such that only authenticated users may connect.
  4. Connect to the MongoDB server from the mongo shell authenticating as user securityofficer
  5. Do a find() on the system.users collection.
  1. Configure and launch a three member MongoDB replica set on your local computer.
  2. Connect to the primary from the mongo shell and create a database called catalog, then insert one document as follows.
use catalog
db.products.insertOne({name: "Coffee Mug", price: 4})
@shannonbradshaw
shannonbradshaw / task-drop-database.rst
Last active July 31, 2016 19:31
Drop Database from the Command Line

Assume you have a MongoDB instance running on the default port. Using bash, powershell, or a similar application, write a statement that will drop a MongoDB database called products_test from the command line.

@shannonbradshaw
shannonbradshaw / task-m-in-name.rst
Last active July 31, 2016 19:44
Task: Users with "m" in Their Name

Suppose you have a users collection in a database named people. Documents in the users collection resemble the following:

{
    _id: 1,
    name: "Gram Parsons",
    DOB: "1946-11-05"
} 
@shannonbradshaw
shannonbradshaw / task-array-containing-specific-value.rst
Created July 31, 2016 19:43
Task: Array Containing Specific Value

Suppose you have a collection called people containing documents that resemble the following:

{ 
    name : "Kay", 
    favoriteFoods : ["mango", "salmon", "quinoa"]
}

In the mongo shell, how would you query for all people listing "mango" as a favorite food?

@shannonbradshaw
shannonbradshaw / task-last-10-items.rst
Last active August 5, 2016 21:34
Task: Last 10 Items

Suppose you have a collection called stories containing documents that resemble the following:

{ 
    _id : ObjectId("579b8063a2f12bdaf5684505"), 
    author : "John Henry",
    name : "Building a Railroad"
}
@shannonbradshaw
shannonbradshaw / task-queried-element-in-array.rst
Last active August 1, 2016 12:19
Task: Queried Element in an Array

Suppose you have a collection called figures containing the following documents.

{ 
    "_id" : 1
    "shapes" : [ 
        { "shape": "square", "color": "blue" }, 
        { "shape": "circle", "color": "red" } 
    ] 
@shannonbradshaw
shannonbradshaw / task-combine-data-from-multiple-collections.rst
Last active August 5, 2016 12:46
Task: Combine Data from Multiple Collections

Suppose you have data about books split into two collections. The first collection, called books, contains the following documents.

{
    "isbn": "978-3-16-148410-0",
    "title": "Some cool book",
    "author": "John Doe"
}
{
@shannonbradshaw
shannonbradshaw / task-add-field-to-document.rst
Last active August 10, 2016 21:57
Add a Field to a Document

Suppose the document below is stored in a collection stories within the database folklore. How would you add a field called year with the value 1913 to this document?

{
    _id : 13,
    author : "John Henry",
    name : "Building a Railroad"
}