Skip to content

Instantly share code, notes, and snippets.

@mongolab-org
mongolab-org / mongoose-connection-settings-example.js
Created December 10, 2017 20:33
mLab-recommended Mongoose driver options for production applications. Note: this example is for the Mongoose 4.3.x driver. For the most up-to-date information on driver settings, please visit the Node.js driver documentation: https://mongodb.github.io/node-mongodb-native/
// 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,
@mongolab-org
mongolab-org / watch-flip-flop.py
Last active August 5, 2016 23:05
check out http://mongolab.org/flip-flop/ for a more detailed explanation
#!/usr/bin/env python
# Written with pymongo-3.3
author__ = 'mongolab' \
import pymongo
import sys, datetime, time
import random
@mongolab-org
mongolab-org / polygon-example.js
Last active August 29, 2015 14:05
MongoDB invalid/valid polygon example
//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": [
@mongolab-org
mongolab-org / geojson-within.js
Last active August 29, 2015 14:05
Find Points within a specified Square using MongoDB GeoJSON support.
db.places.find( { loc :
{ $geoWithin :
{ $geometry :
{ type : "Polygon",
coordinates : [ [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 0 , 0 ] ] ]
} } } } )
// 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
@mongolab-org
mongolab-org / coordinate-pair-within.js
Created August 18, 2014 05:37
Find Points within a specified Square using MongoDB $polygon operator.
db.places.find( { loc :
{ $geoWithin :
{ $polygon :
[ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ]
} } } )
@mongolab-org
mongolab-org / legacy-proximity.js
Last active August 29, 2015 14:05
MongoDB proximity query using legacy coordinate pairs
db.places.find( { loc :
{ $near : [ 100 , 100 ],
$maxDistance: 10 }
} )
@mongolab-org
mongolab-org / coordinate-pair.js
Last active August 29, 2015 14:05
MongoDB legacy coordinate pairs
{
name : "Timmy's Taco Truck",
loc : [ 37.7577 , -122.4376 ]
}