Vous êtes sur la page 1sur 3

(/)

Courses (/courses) Help (/help) About (/about) Blog (http://ed-blog.mongodb.com/) DMAKETAS (/DASHBOARD)

M101J: MongoDB for Java Developers


Courseware (/courses/10gen/M101J/2013_October/courseware) Discussion (/courses/10gen/M101J/2013_October/discussion/forum) Progress (/courses/10gen/M101J/2013_October/progress) Course Info (/courses/10gen/M101J/2013_October/info) Wiki (/courses/10gen/M101J/2013_October/course_wiki)

SEARCH

Homework: HW 3.2
Making your blog accept posts In this homework you will be enhancing the blog project to insert entries into the posts collection. After this, the blog will work. It will allow you to add blog posts with a title, body and tags and have it be added to the posts collection properly. We have provided the code that creates users and allows you to login (the assignment from last week). To get started, please download hw3-2and3-3.tar (/static/m101j-october-2013/handouts/hw3-2and3-3.49c823a59883.tar) or hw3-2and3-3.zip (/static/m101j-october-2013/handouts/hw3-2and3-3.7441bbb37b6e.zip) and unpack. You will be using these file for this homework and the HW 3.3. The areas where you need to add code are marked with XXX. You need only touch the BlogPostDAO class. There are three locations for you to add code for this problem. Scan that file for XXX to see where to work. Here is an example of valid blog post:

>d b . p o s t s . f i n d ( ) . p r e t t y ( ) { " _ i d ":O b j e c t I d ( " 5 1 3 d 3 9 6 d a 0 e e 6 e 5 8 9 8 7 b a e 7 4 " ) , " t i t l e ":" M a r t i a n st ou s eM o n g o D B " , " a u t h o r ":" a n d r e w " , " b o d y ":" R e p r e s e n t a t i v e sf r o mt h ep l a n e tM a r sa n n o u n c e dt o d a yt h a tt h ep l a n e tw o u l da d o p tM o n g o D Ba sa p l a n e t a r ys t a n d a r d .H e a dM a r t i a nF l i p b l i ps a i dt h a tM o n g o D Bw a st h ep e r f e c tt o o lt os t o r et h ed i v e r s i t yo fl i f e t h a te x i s t so nM a r s . " , " p e r m a l i n k ":" m a r t i a n s _ t o _ u s e _ m o n g o d b " , " t a g s ":[ " m a r t i a n s " , " s e t i " , " n o s q l " , " w o r l d d o m i n a t i o n " ] , " c o m m e n t s ":[] , " d a t e ":I S O D a t e ( " 2 0 1 3 0 3 1 1 T 0 1 : 5 4 : 5 3 . 6 9 2 Z " )

" d a t e ":I S O D a t e ( " 2 0 1 3 0 3 1 1 T 0 1 : 5 4 : 5 3 . 6 9 2 Z " ) }

As a reminder, to run your blog you type


m v nc o m p i l ee x e c : j a v aD e x e c . m a i n C l a s s = c o u r s e . B l o g C o n t r o l l e r

Or, use an IDE to run it. To play with the blog you can navigate to the following URLs
h t t p : / / l o c a l h o s t : 8 0 8 2 / h t t p : / / l o c a l h o s t : 8 0 8 2 / s i g n u p h t t p : / / l o c a l h o s t : 8 0 8 2 / l o g i n h t t p : / / l o c a l h o s t : 8 0 8 2 / n e w p o s t

You will be proving that it works by running our validation script as follows:
p y t h o nv a l i d a t e . p y

You need to run this in a separate terminal window while your blog is running and while the database is running. It makes connections to both to determine if your program works properly. Validate connects to localhost:8082 and expects that mongod is running on localhost on port 27017. Read if you want to run your blog on non-standard port, different host or connected to a mongod on different server.
By popular demand, validate.py now takes some optional arguments that you can discover with the -h flag. These arguments will allow you to direct validate.py to make a connection to a web server at different port on a different host and connect to a mongod on a different host. You can also use a database name other than blog, a necessity if you are running on the free tier at MongoHW (for eg). I won't go into how these arguments work, as they are

pretty self documenting. Note that to run the blog.py code to connect to a database outside of localhost (for example to a database at MongoHQ), you will need to make some global changes.

The python validator requires Python 2.7. The code is not 3.0 compliant. Ok, once you get the blog posts working, validate.py will print out a validation code for HW 3.2. Please enter it below, exactly as shown with no spaces.
1

njkfd489hj9fhds8934kf23 HIDE ANSWER You have used 0 of 3 submissions

Products & Services (http://www.mongodb.com/products/mongodb) Events (http://www.mongodb.com/events) Partners (http://www.mongodb.com/partners) Customers (http://www.mongodb.com/customers) About MongoDB (http://www.mongodb.com/about) Contact Us (/contact) Careers (http://www.mongodb.com/careers)

(https://twitter.com/mongodbinc)

(http://www.facebook.com/mongodb)

(http://www.linkedin.com/company/783611)

(https://plus.google.com/101024085748034940765/posts) (http://edx.org) (http://www.mongodb.com)


2013 MongoDB, Inc. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB Inc.

Vous aimerez peut-être aussi