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