MongoSF - Spatial MongoDB in OpenShift - script file
Upcoming SlideShare
Loading in...5
×
 

MongoSF - Spatial MongoDB in OpenShift - script file

on

  • 654 views

The script used to run the demo portion of my talk for MongoSF

The script used to run the demo portion of my talk for MongoSF

Statistics

Views

Total Views
654
Views on SlideShare
654
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    MongoSF - Spatial MongoDB in OpenShift - script file MongoSF - Spatial MongoDB in OpenShift - script file Presentation Transcript

    • 1 #commands for adding spatial data! 2 ! 3 #Take a look at the file first! 4 less parkcoord.json! 5 #get the file on the server! 6 scp parkcoord.json 0b49d9219f2847c6a236820959f9a@parks-spmongo.rhcloud.com:parks/data/! 7 ! 8 #ssh into the machine! 9 ssh 0b49d9219f2847c6a236820959f9a@parks-spmongo.rhcloud.com!10 !11 #import into mongo!12 mongoimport -d parks -c mongosf --type json --file parks/data/parkcoord.json -h $OPENSHIFT_NOSQL_DB_HOST -u admin -p <your … password>!13 !14 #open the mongo shell!15 mongo -u admin -p <your password> $OPENSHIFT_NOSQL_DB_HOST/parks!16 !17 #build the index!18 db.mongosf.ensureIndex({"pos":"2d"});!19 !20 #Now some queries!21 #simple spatial!22 db.mongosf.find({"pos" : { "$near" : [-37, 41]}});!23 !24 #spatial and text query using regex!25 db.mongosf.find( { Name : /lincoln/i, pos : { $near : [-37,41] }} );!26 !27 #geonear TODO!28 db.runCommand({ geoNear : "mongosf", near : [-37,41], num : 10 });!29 !30 !31 #create a new collection from scratch!32 db.createCollection("mongosfuserloc");!33 db.mongosfuserloc.ensureIndex( { pos : "2d" } );!34 !35 #insert a new record!36 db.mongosfuserloc.insert({ "created" : new Date(), "Notes" : just landed, "pos" : [-76.7302 , 25.5332 ] })!37 ! !38 #quick query to make sure it worked!39 db.mongosfuserloc.find( { pos : { $near : [-37,41] } } )!40 !41 #add a second document closer to query point!42 #this is an upsert - since we dont pass in the _id it creates a new record!43 db.mongosfuserloc.save({ created : new Date(), Notes: that was a big step, pos : [-37.7302 , 40.5332 ]});!44 !45 #one way to update original document!46 myDoc = db.mongosfuserloc.findOne({_id : ObjectId("ID for the first object")});!47 myDoc.Notes = "really the landing";!48 db.mongosfuserloc.save(myDoc);!49