Angel \”Java\” Lopez on Blog

October 22, 2013

SharpMongo (2) a REPL

Filed under: C Sharp, MongoDB, NoSQL, Open Source Projects, SharpMongo — ajlopez @ 7:15 pm

Previous Post

I’m working on my document in-memory store project, written in C#

https://github.com/ajlopez/SharpMongo

It tries to implement the same operations as MongoDB: to have document bases, collections, documents, dynamic objects, etc. But with a difference: all is in-memory, and by now, in the same process. Persistence will be added as a plugin.

One of the tools I wanted to build is a REPL (Read Eval Print Loop), a console program that emulates the main functions of the MongoDB console client. The MongoDB program talks againts a server. SharpMongo, in the current version, only works in the same process memory, no persistence is implemented, yet.

The project is SharpMongo.Console. It compiles an assembly named sharpmongo.exe. You can launch it from command line:

SharpMongo 0.0.1
> show dbs
> show collections
> use foo
> show dbs
foo  

Now, we are in a db (document base), named ‘foo’. We can create a collection inserting dynamic documens, in a JSON-like format:

> db.people.insert({ Name: 'Adam', Age: 800 })
> db.people.insert({ Name: 'Eve', Age: 700 })
> show collections
people  

We can find the documents in a collection:

  > db.people.find()
{ "Name": "Adam", "Age": 800, "Id": 4d802e11-a038-468e-bd26-38e96ad6f7d8 }
{ "Name": "Eve", "Age": 700, "Id": b29917f1-70f1-4f6c-95bb-f789fa9bf3c0 }  

We can find documents, filtering them using a criteria, expressed in a dinamic object as first parameter (a la query by example):

  > db.people.find({ Name: 'Adam' })
{ "Name": "Adam", "Age": 800, "Id": 4d802e11-a038-468e-bd26-38e96ad6f7d8 }  

We can insert more documents:

> db.people.insert({ Name: 'Cain', Age: 600 })
> db.people.insert({ Name: 'Abel', Age: 500 })
> db.people.find()
{ "Name": "Adam", "Age": 800, "Id": 4d802e11-a038-468e-bd26-38e96ad6f7d8 }
{ "Name": "Eve", "Age": 700, "Id": b29917f1-70f1-4f6c-95bb-f789fa9bf3c0 }
{ "Name": "Cain", "Age": 600, "Id": a5a3e1af-7e5c-4c16-829e-c07f94bc8697 }
{ "Name": "Abel", "Age": 500, "Id": c1da0055-8ded-4540-876f-5c032f514ed3 }  

We can insert and remove documents:

> db.people.insert({ Name: 'Pluto' })
> db.people.find()
{ "Name": "Adam", "Age": 800, "Id": 4d802e11-a038-468e-bd26-38e96ad6f7d8 }
{ "Name": "Eve", "Age": 700, "Id": b29917f1-70f1-4f6c-95bb-f789fa9bf3c0 }
{ "Name": "Cain", "Age": 600, "Id": a5a3e1af-7e5c-4c16-829e-c07f94bc8697 }
{ "Name": "Abel", "Age": 500, "Id": c1da0055-8ded-4540-876f-5c032f514ed3 }
{ "Name": "Pluto", "Id": 0561864a-470a-4437-9467-773ffb5a438a }
> db.people.remove({ Name: 'Pluto' })
> db.people.find()
{ "Name": "Adam", "Age": 800, "Id": 4d802e11-a038-468e-bd26-38e96ad6f7d8 }
{ "Name": "Eve", "Age": 700, "Id": b29917f1-70f1-4f6c-95bb-f789fa9bf3c0 }
{ "Name": "Cain", "Age": 600, "Id": a5a3e1af-7e5c-4c16-829e-c07f94bc8697 }
{ "Name": "Abel", "Age": 500, "Id": c1da0055-8ded-4540-876f-5c032f514ed3 }   

There are missing parts, the most important one could be the support of operators in query objects, that could allow us to apply more complex criteria, beyond equality, and operators in the update operation. All will be added using TDD, as usual.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

1 Comment »

  1. […] Next Post […]

    Pingback by SharpMongo (1) First Classes | Angel "Java" Lopez on Blog — October 22, 2013 @ 7:16 pm


RSS feed for comments on this post. TrackBack URI

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

Create a free website or blog at WordPress.com.

%d bloggers like this: