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
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