This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Finding a "start" point | |
| > use proximity | |
| switched to db proximity | |
| > doc | |
| { | |
| "loc" : { | |
| "type" : "LineString", | |
| "coordinates" : [ | |
| [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongoose = require('mongoose'); | |
| var mongoUri = 'mongodb://localhost:27017/mongoquest'; | |
| mongoose.connect(mongoUri); | |
| mongoose.connection.on("open", function() { /* adventure! */ ; }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add extension=mongo.so to your php.ini file. | |
| $m = new Mongo('mongodb://user:pass@localhost:27017/dbname'); | |
| $db = $m->dbname; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pymongo | |
| mongo_uri = 'mongodb://user:pass@localhost:27017/dbname' | |
| db_name = 'dbname' | |
| connection = pymongo.Connection(mongo_uri) | |
| db = connection[db_name] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
NewerOlder