spatial script for mongoboulder

Download Spatial script for MongoBoulder

If you can't read please download the document

Upload: steven-pousty

Post on 23-Jun-2015

299 views

Category:

Technology


0 download

DESCRIPTION

The Script I

TRANSCRIPT

  • 1. #commands for adding spatial data#Take a look at the file first#less parkcoord.json#get the file on the serverscp parkcoord.json [email protected]:app-root/data#ssh into the machinessh [email protected]#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. #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);