This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run: | |
system.indexes | |
system.users | |
BUILD SUCCESSFUL (total time: 1 second) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Finally, let's do a basic iteration and display the names of the collections in the NetBeans console. | |
public static void main(String[] args) throws UnknownHostException { | |
Mongo m = new Mongo( "hatch.mongohq.com" , 10004 ); | |
DB db = m.getDB("my_database_name"); | |
boolean auth = db.authenticate("cloudbees", "my_database_password".toCharArray()); | |
Set<String> my_collections = db.getCollectionNames(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here, we are adding a string named "my_collections" that will hold the names of the collection. | |
public static void main(String[] args) throws UnknownHostException { | |
Mongo m = new Mongo( "hatch.mongohq.com" , 10004 ); | |
DB db = m.getDB("my_database_name"); | |
boolean auth = db.authenticate("cloudbees", "my_database_password".toCharArray()); | |
Set<String> my_collections = db.getCollectionNames(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// One final step ... for the main method, we need to provide a way for it to | |
// throw an error if we cannot connect to the MongoHQ database. | |
public static void main(String[] args) throws UnknownHostException { | |
Mongo m = new Mongo( "hatch.mongohq.com" , 10004 ); | |
DB db = m.getDB("my_database_name"); | |
boolean auth = db.authenticate("cloudbees", "my_database_password".toCharArray()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspecting what the Mongo library makes available, we see that we will | |
// need the following: | |
// A Mongo class that takes the server name and the port. | |
// A DB class that takes the name of the database | |
// Declare a boolean variable that will hold the authentication status of the authenticate method on the db object. | |
public static void main(String[] args) { | |
Mongo m = new Mongo( "hatch.mongohq.com" , 10004 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.UnknownHostException; | |
import java.util.Set; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mongodb.Mongo; | |
import com.mongodb.DB; | |
import com.mongodb.DBCollection; | |
import com.mongodb.BasicDBObject; | |
import com.mongodb.DBObject; | |
import com.mongodb.DBCursor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Index() | |
{ | |
var model = new DeveloperModel(); | |
var developers_collection = mongo_db.GetCollection("developers").FindAll().AsEnumerable(); | |
model.developers = (from developer in developers_collection | |
select new DeveloperDTO | |
{ | |
id = developer["_id"].AsObjectId, | |
name = developer["name"].AsString, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<mongohq_csharp.Models.DeveloperModel>" %> | |
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> | |
Index | |
</asp:Content> | |
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> | |
<h2>Developers</h2> |