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
| <?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
| 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
| > 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
| 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
| print(' ') | |
| printShardingStatus() | |
| db.runCommand({enablesharding : 'fred_sharded'}) | |
| db.runCommand({enablesharding : 'fred_sharded2'}) | |
| db.runCommand({shardcollection : 'fred_sharded.temp', key:{'_id':1}}) | |
| db.runCommand({shardcollection : 'fred_sharded2.temp', key:{'_id':1}}) | |
| db2 = db.getSisterDB('fred_sharded') | |
| db3 = db.getSisterDB('fred_sharded2') |
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
| Method One: Array of Objects | |
| ------ | |
| var pd = { type: "Person", attributes: [{name: "Penelope Doe"},{age: 26}] }; | |
| var pd2 = { type: "Person", attributes: [ {name: "Johnny Doe"},{age: 27} ] }; | |
| db.foo.drop(); | |
| db.foo.save(pd); | |
| db.foo.save(pd2); | |
| db.foo.ensureIndex({attributes:1}) | |
| db.foo.find({'attributes' : {age : {$gt : 26 } } }).count() | |
| db.foo.find({'attributes' : {age : {$gt : 26 } } }).explain() |
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 d = { | |
| ... drives:{ | |
| ... C:{ | |
| ... windows:{ | |
| ... 'explorer':{ | |
| ... admin:'r+w' | |
| ... } | |
| ... } | |
| ... } | |
| ... } |
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
| // Define function | |
| subset = function (test, superset) { | |
| if (test.length > superset.length) { | |
| return false; | |
| } | |
| for (var i in test) { | |
| found = false; | |
| for (var j in superset) { | |
| found = found || superset[j] == test[i]; | |
| } |
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
| function df { | |
| $colItems = Get-wmiObject -class "Win32_LogicalDisk" -namespace "root\CIMV2" ` | |
| -computername localhost | |
| foreach ($objItem in $colItems) { | |
| write $objItem.DeviceID $objItem.Description $objItem.FileSystem ` | |
| ($objItem.Size / 1GB).ToString("f3") ($objItem.FreeSpace / 1GB).ToString("f3") | |
| } |