#commands for adding spatial data#Take a look at the file first#less parkcoord.json#get the file on the serverscp parkcoor...
#create a new collection from scratchdb.createCollection("checkin");db.checkin.ensureIndex( { "pos" : "2d" } );#insert a n...
Upcoming SlideShare
Loading in...5
×

Spatial script for MongoBoulder

310

Published on

The Script I

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

  • Be the first to like this

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

No notes for slide

Transcript of "Spatial script for MongoBoulder"

  1. 1. #commands for adding spatial data#Take a look at the file first#less parkcoord.json#get the file on the serverscp parkcoord.json 30bb1262b1364026855e358a649f171b@parks-spmongo.rhcloud.com:app-root/data#ssh into the machinessh 30bb1262b1364026855e358a649f171b@parks-spmongo.rhcloud.com#import into mongomongoimport -d parks -c parkpoints --type json --file app-root/data/parkcoord.json -h$OPENSHIFT_NOSQL_DB_HOST -u admin -p $OPENSHIFT_NOSQL_DB_PASSWORD#open the mongo shellmongo#build the indexdb.parkpoints.ensureIndex({"pos":"2d"});#Now some queries##simple spatialdb.parkpoints.find({"pos" : { "$near" : [-37, 41]}});db.parkpoints.find({"pos" : { "$nearSphere" : [-37, 41]}});##bbox querydb.parkpoints.find( { "pos": { "$within": { "$box": [ [-70, 30] , [-82, 40] ] } } } )#spatial and text query using regexdb.parkpoints.find( { Name : /lincoln/i, pos : { $near : [-37,41] }} );#geoneardb.runCommand({ geoNear : "parkpoints", near : [-37,41], num : 10 });db.runCommand({ geoNear : "parkpoints", spherical: true, near : [-37,41], num : 10 });db.runCommand({ geoNear : "parkpoints", spherical: true, distanceMultiplier: 3963.192, near : [-37,41], num : 10 });https://github.com/openshift/openshift-mongo-node-express-examplehttp://nodewsos-spdemo.rhcloud.com/ws/parks
  2. 2. #create a new collection from scratchdb.createCollection("checkin");db.checkin.ensureIndex( { "pos" : "2d" } );#insert a new recorddb.checkin.insert({ "created" : new Date(), "Notes" : just landed, "pos" : [-76.7302 , 25.5332 ] })#quick query to make sure it workeddb.checkin.find( { pos : { $near : [-37,41] } } )#add a second document closer to query point#this is an upsert - since we dont pass in the _id it creates a new recorddb.checkin.save({ created : new Date(), Notes: that was a big step, pos : [-37.7302 , 40.5332 ]});#one way to update original documentmyDoc = db.checkin.findOne({_id : ObjectId("50130d8ea8f6532e83026bc1")});myDoc.Notes = "really the landing";db.checkin.save(myDoc);

×