Instantly share code, notes, and snippets.

View mongoose-connection-settings-example.js
// Recommended driver settings for the Mongoose 4.3.x driver.
var mongoose = require('mongoose');
var uri = 'mongodb://<dbuser>:<dbpassword>@<host1>:<port1>,<host2>:<port2>/<dbname>?replicaSet=<replicaSetName>';
var options = {
"server" : {
"socketOptions" : {
"keepAlive" : 300000,
View polygon-example.js
//Invalid - Each point/vertex of the polygon is provided.
{ "type": "Polygon",
"coordinates": [
[ [ 100.0 , 0.0 ] , [ 101.0 , 0.0 ] , [ 101.0 , 1.0 ] , [ 100.0 , 1.0 ] ]
]
}
//Valid - First vertex of the polygon is provided at both the beginning and end of a LinearRing.
{ "type": "Polygon",
"coordinates": [
View geojson-within.js
db.places.find( { loc :
{ $geoWithin :
{ $geometry :
{ type : "Polygon",
coordinates : [ [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 0 , 0 ] ] ]
} } } } )
View geojson.js
// Point representation of Timmy's Taco Truck
{
name : "Timmy's Taco Truck",
loc : {
type : "Point",
coordinates : [ 37.7577 , -122.4376 ]
}
}
// Polygon representation (Square) of a Food Truck Park
View coordinate-pair-within.js
db.places.find( { loc :
{ $geoWithin :
{ $polygon :
[ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ]
} } } )
View legacy-proximity.js
db.places.find( { loc :
{ $near : [ 100 , 100 ],
$maxDistance: 10 }
} )
View coordinate-pair.js
{
name : "Timmy's Taco Truck",
loc : [ 37.7577 , -122.4376 ]
}
View watch-flip-flop.py
#!/usr/bin/env python
# Written with pymongo-3.3
author__ = 'mongolab' \
import pymongo
import sys, datetime, time
import random