Your SlideShare is downloading. ×
Spatial script for Spatial mongo for PHP and Zend
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Spatial script for Spatial mongo for PHP and Zend

458

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×