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
| Original Collection | |
| Array | |
| ( | |
| [_id] => MongoId Object | |
| ( | |
| [$id] => 4d963aa56803fa8318000000 | |
| ) | |
| [owner] => 1 | |
| [type] => question |
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.locations.insert({coords: [-79.4434, 44.1428], type: 'bank', tags:['24h', 'finance']}) | |
| > db.locations.insert({coords: [-62.0343, 45.4432], type: 'cinema', tags: ['film', 'popcorn']}) | |
| > db.locations.insert({coords: [-64.3433, 45.3341], type: 'cafe', tags: ['coffee', 'tea']}) | |
| > db.locations.distinct('type') | |
| [ "bank", "cinema", "cafe" ] | |
| > db.locations.ensureIndex({ type : 1 }) | |
| > db.locations.distinct('type') | |
| [ "bank", "cafe", "cinema" ] | |
| > db.locations.ensureIndex({coords: '2d', type: 1, tags: 1}) | |
| > db.locations.distinct('type') |
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
| randomString = function(string_length) { | |
| var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; | |
| var randomstring = ''; | |
| for (var i=0; i<string_length; i++) { | |
| var rnum = Math.floor(Math.random() * chars.length); | |
| randomstring += chars.substring(rnum,rnum+1); | |
| } | |
| return randomstring; | |
| } |
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
| <?php | |
| $mongo = new Mongo(); | |
| $coll = $mongo->selectCollection('foo', 'documents'); | |
| $coll->drop(); | |
| $coll->insert( array( "bar foo" => array( 'bah baz' => 2 ) ) ); | |
| $res = $coll->find(array('bar foo.bah baz' => 2)); | |
| foreach($res as $r){ |
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.foo.drop(); | |
| db.foo.insert( { actor: "Richard Gere", movies: ['Pretty Woman', 'Runaway Bride', 'Chicago'] }) | |
| db.foo.insert( { actor: "Julia Roberts", movies: ['Pretty Woman', 'Runaway Bride', 'Erin Brockovich'] }) | |
| map = function() { | |
| for(var i in this.movies){ | |
| key = { movie: this.movies[i] }; | |
| value = { actors: [ this.actor ] }; | |
| emit(key, value); | |
| } |
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 x = { | |
| "_id" : ObjectId("4dbf16ecee3bbe4d22000003"), | |
| "options" : { | |
| "options" : [ { "price" : { "_type" : "decimal", "val" : 1000 }, "label" : "10" } | |
| ], | |
| "categories" : [[ "WTF","11" ]] | |
| } | |
| } | |
| db.deals_test.drop(); |
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.foo.insert( { x : 1, y : 1 } ) | |
| > db.foo.insert( { x : 2, y : "string" } ) | |
| > db.foo.insert( { x : 3, y : null } ) | |
| > db.foo.insert( { x : 4 } ) | |
| > db.foo.find() | |
| { "_id" : ObjectId("4dc1974612c677fc83b5629d"), "x" : 1, "y" : 1 } | |
| { "_id" : ObjectId("4dc1974c12c677fc83b5629e"), "x" : 2, "y" : "string" } | |
| { "_id" : ObjectId("4dc1975312c677fc83b5629f"), "x" : 3, "y" : null } | |
| { "_id" : ObjectId("4dc1975a12c677fc83b562a0"), "x" : 4 } | |
| > db.foo.find( { "y" : null } ) |
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
| <?php | |
| try{ | |
| $m = new Mongo('localhost'); | |
| $db = $m->abc; | |
| $collection = $db->def; | |
| $collection->drop(); | |
| // Insert test data | |
| $collection->insert( array('A' => 1, 'B' => 4, 'C' => array("C1" => 'val', "C2" => 15) ) ); |
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
| <?php | |
| try{ | |
| $m = new Mongo('localhost'); | |
| $db = $m->abc; | |
| $collection = $db->def; | |
| $collection->drop(); | |
| // Insert test data | |
| $collection->insert( array('A' => 1, 'B' => 4, 'C' => array("C1" => 'val', "C2" => 15) ) ); |
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
| <?php | |
| try{ | |
| ### Step 1 & 2 | |
| $m = new Mongo('ec2-50-16-121-178.compute-1.amazonaws.com'); | |
| $db = $m->admin; | |
| ### Step 3 | |
| $res = $db->command(array('replSetGetStatus' => 1)); | |
| print_r($res); |