1   #commands for adding spatial data! 2   ! 3   #Take a look at the file first! 4   less parkcoord.json! 5   #get the fil...
Upcoming SlideShare
Loading in...5
×

MongoSF - Spatial MongoDB in OpenShift - script file

483

Published on

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

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
483
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MongoSF - Spatial MongoDB in OpenShift - script file

  1. 1. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×