Showing posts with label MongoDb. Show all posts
Showing posts with label MongoDb. Show all posts

Thursday, May 22, 2014

Triangular Meetup May 2014

I went to the Tri-angular meetup and learned about the mean stack (Mongo-Express-Angular-Node). This was held at Ignite Social Media hosted by Darrough West and Keith Morgan.

There is mean.io and meanjs.org . It was suggested its easy to obtain it and get it built just using the node package manager (npm install).  The io one is better choice  as it has an SLA, but they are both pretty similar. However, it is rapidly changing and it does not have a released version.

Passportjs is baked in.

They host their projects on Heroku with MongoHQ.

Koa was mentioned as the "next" express.

Angular and node each have their own routing, but Angular routing invokes the Node routing.

Angular boiler plate was mentioned.

Suggestions with angular:
Try not overload scope, Template cache helpful

Html5 polyfill, respond.js for dealing with ie8

Do not put JQuery in controllers

Promises built in

Factories for http calls

Providers are fancy plugins

No need for undersore, but people like the map/reduce functions

lo-dash a underscre alternative

meteor use on sockets

mention of mongoose

Related post.

Sunday, October 20, 2013

Week 2 of MongoDB


I have not had the time to do the homework for week 1, but i finished the lectures finally.

https://education.mongodb.com/static/m101j-october-2013/handouts/hw1-1.184820ec29b6.zip
https://education.mongodb.com/static/m101j-october-2013/handouts/hw1-3.2005b1d3b047.zip
https://education.mongodb.com/static/m101j-october-2013/handouts/hw1-4.b2846101dcff.zip



Here is the link for week 2

https://education.mongodb.com/courses/10gen/M101J/2013_October/courseware/Week_2_-_CRUD/Introduction_to_Week_2/

Saturday, October 12, 2013

MongoDB Week 1

I started the MongoDB for Java developer course this week.

The lead developer of the java driver Jeff Yemin along with Andrew Erlichson are the instructors.


Non relational algebra

Json store

Json documents - collection of documents


Key values



Mongoshell - tcpconnects to mongodb

Sparq java - routes to urls
Freemarker mvc









Copy files in bin dir to c:\mongodb226

Make data dir under c drive, Under data mkdir db

Go to bin dir

c:\mongodb226>mongod
mongod --help for help and startup options
Tue Oct 08 22:44:36 [initandlisten] MongoDB starting : pid=1696 port=27017 dbpath=\data\db
\ 64-bit host=CSGRALLT10
Tue Oct 08 22:44:36 [initandlisten] db version v2.2.6, pdfile version 4.5


c:\mongodb226>mongo
MongoDB shell version: 2.2.6
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
> 

Or
mongo localhost

> db
test


      
> show collections
> db.mycollections.insert({text:'hello world'})
> show collections
mycollections
system.indexes
> db.mycollections.find()
{ "_id" : ObjectId("5254c64c2488183e2c3d49f8"), "text" : "hello world" }
> 



c:\>cd data

c:\data>cd db

c:\data\db>dir
 Volume in drive C is Windows
 Volume Serial Number is 1CEC-CA9A

 Directory of c:\data\db

10/08/2013  10:58 PM    <DIR>          .
10/08/2013  10:58 PM    <DIR>          ..
10/08/2013  10:58 PM    <DIR>          journal
10/08/2013  10:50 PM                 6 mongod.lock
10/08/2013  10:58 PM        67,108,864 test.0
10/08/2013  10:58 PM       134,217,728 test.1
10/08/2013  10:58 PM        16,777,216 test.ns
10/08/2013  10:58 PM    <DIR>          _tmp
               4 File(s)    218,103,814 bytes
               4 Dir(s)  49,962,684,416 bytes free





> mvn archetype:generate

enter 308 at prompt
    308: remote -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which
ven project.)



              308

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 308:
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1

Choose a number: 6: 6
 mvn compile exec:java -Dexec.mainClass="org.mongodb.App"



           <dependency>
              <groupId>org.mongodb</groupId>
              <artifactId>mongo-java-driver</artifactId>
               <version>2.10.1</version>
            </dependency>
import com.mongodb.DB; 
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;

public class HelloMongoDB {

public static void main( String[] args ) throws UnknownHostException
{
MongoClient mongoStyleClient = new MongoClient(new ServerAddress("localhost", 27017));
           DB db = mongoStyleClient.getDB("test");
           System.out.println( "Hello World!" );
  DBCollection coll = db.getCollection("mycollections");
  DBObject document1 = coll.findOne();
  System.out.println(document1); }
}}
 Hello World!
{ "_id" : { "$oid" : "5254c64c2488183e2c3d49f8"} , "text" : "hello world"}

Spark Web Application Framework

http://www.sparkjava.com/

<repositories>
      <repository>
          <id>Spark repository</id>
          <url>http://www.sparkjava.com/nexus/content/repositories/spark/</url>
      </repository>
  </repositories>


<dependency>
      <groupId>spark</groupId>
      <artifactId>spark</artifactId>
      <version>0.9.9.4-SNAPSHOT</version>
     </dependency>


import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;


public class HelloWorldSparkStyle {

public static void main( String[] args )
    {
   
      //http://localhost:4567/
        Spark.get(new Route("/") {

@Override
public Object handle(Request arg0, Response arg1) {

return "Hello Spark World!";
}
});
     
    }

}

Hello Spark World!

Template library
http://freemarker.org/

.ftl files combined with data map


      <dependency>
      <groupId>org.freemarker</groupId>
      <artifactId>freemarker</artifactId>
      <version>2.3.19</version>
     </dependency>



Spark - Http Get , Http Post


Freemarker looping




Freemarker ...

Spark.post(new Route("/favorite_fruit")

Schemaless Mongodb example (can add columns on fly)

json - arrrays, dictionaries (associated maps)




MongoPosts

16meg limit on document