1

Click here to load reader

MongoSF - Spatial MongoDB in OpenShift - script file

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: MongoSF - Spatial MongoDB in OpenShift - script file

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

49