Spatial script for Spatial mongo for PHP and Zend

  • 414 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
414
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
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