softwaremom

Just another WordPress.com site

Last Week’s Learning on C# programming on MongoDB

Over the week, I had done the following:

1. On Windows, played with MongoDB C# and the Linq adaptor.  The sample tutorial (http://docs.mongodb.org/ecosystem/tutorial/use-linq-queries-with-csharp-driver/)  shows that you have to declare a POCO class that expose one particular property:

public class Entity
{
    public ObjectId Id { get; set; }

    public string Name { get; set; }
}

Then, after created a 

var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("test"); // "test" is the name of the database
// "entities" is the name of the collection var collection = database.GetCollection<Entity>("entities");

After that, you can insert a new document by using collection.Insert, query the collection by 

var query = Query<Entity>.EQ(e => e.<field name>, <field value to Search>);
var entity = collection.FindOne(query);

Or, use Set or Save methods to modify the document.

However, I feel that there must be another sets of APIs that allows type-less access to the database. The beauty of NoSQL is that it allows schema-less design.  I saw that some of the methods has a different type of interface so perhaps that’s what it’s for.  Will explore that later.

2.  I’ve installed Ubuntu on my retired Windows PC and put Java and Hadoop on it.  This time, I used the Cloudera CDH package so things went a lot smoother.  Everything uses the default install and there’s no need to modify the site.xml files.  These are all very new to me so I am not 100% understanding what went on.  But, the WordCount sample code compile and run.

I’ve created 2 shell script files in my ~/bin folder.  hadoop-hdfs-start and hadoop-hdfs-stop for starting and stopping all the processes for hadoop, mapred, and yarn.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: