Skip to content

Instantly share code, notes, and snippets.

// Finding a "start" point
> use proximity
switched to db proximity
> doc
{
"loc" : {
"type" : "LineString",
"coordinates" : [
[
@esedor
esedor / gist:1368293
Created November 15, 2011 20:47
Querying MongoDB in Node.JS
mongoose.connection.db.collection('quests', function(err, coll) {
coll.insert({'goal': 'Explore a new land', 'level': 1});
coll.update({'goal': 'Explore a new land'},
{'$set': {'reward.gold': 150}});
coll.find({'level': {'$lte': 4}}).toArray(function (err, result) {
console.log(result);
});
});
@esedor
esedor / gist:1368275
Created November 15, 2011 20:40
Connecting to MongoDB in Node.JS
var mongoose = require('mongoose');
var mongoUri = 'mongodb://localhost:27017/mongoquest';
mongoose.connect(mongoUri);
mongoose.connection.on("open", function() { /* adventure! */ ; });
@esedor
esedor / gist:1356731
Created November 11, 2011 00:25
Querying MongoDB in PHP
$collection = $db->Spells;
$collection->insert(array('name' => 'Blast', 'level' => 2));
$collection->update(array('name' => 'Blast'),
array('$set' => array('flavortext' => 'FWOOM!')));
$resultcursor = $collection->find(array('level' => 2));
@esedor
esedor / gist:1356730
Created November 11, 2011 00:22
Querying MongoDB in Python
db.adventurers.insert({'name': 'Cooper',
'class': 'fighter',
'level': 5})
db.adventurers.update({'name': 'Cooper' },
{'$set': {'level': 6}})
lvl_constraint = {'level': {'$gte': 6}}
result_cursor = db.adventurers.find(lvl_constraint)
@esedor
esedor / gist:1356703
Created November 11, 2011 00:08
Querying MongoDB in Java
locations = database.getCollection("locations");
locations.insert(new BasicDBObject("name", "Arganis"));
locations.update(new BasicDBObject("name", "Arganis"),
new BasicDBObject("$set",
new BasicDBObject("leader",
"King Argan III")));
DBCursor results = locations.find(new BasicDBObject("leader", "King Argan III"));
@esedor
esedor / gist:1356691
Created November 11, 2011 00:03
Querying MongoDB in Ruby
col = db.collection('items')
col.insert({'name' => 'sword', 'size' => 3, 'cost' => 4})
col.find({'size' => { '$gt' => 2 }}).each { |result| puts result }
col.update({'cost' => {'$gt' => 3}}, {'$inc' => {'cost' => -1}}, :multi => true)
@esedor
esedor / gist:1348686
Created November 8, 2011 18:43
New MongoDB Connection in PHP
// Add extension=mongo.so to your php.ini file.
$m = new Mongo('mongodb://user:pass@localhost:27017/dbname');
$db = $m->dbname;
@esedor
esedor / gist:1348675
Created November 8, 2011 18:40
New MongoDB Connection in Python
import pymongo
mongo_uri = 'mongodb://user:pass@localhost:27017/dbname'
db_name = 'dbname'
connection = pymongo.Connection(mongo_uri)
db = connection[db_name]
@esedor
esedor / gist:1348665
Created November 8, 2011 18:38
New MongoDB Connection in Ruby
require 'mongo'
mongo_uri = 'mongodb://user:pass@localhost:27017/dbname'
db_name = 'dbname'
connection = Mongo::Connection.from_uri(mongo_uri)
db = connection.db(db_name)