-
-
Save demesew/90a924dbaa65f6d8c3834cb237a008c1 to your computer and use it in GitHub Desktop.
Revisions
-
dimitardanailov revised this gist
Mar 2, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,8 @@ mongoimport -d crunchbase -c companies companies.json # Change Storage Engine and Database location. mongod -dbpath WT -storageEngine wiredTiger # Example mongod --storageEngine wiredTiger --dbpath /data/wt # Create a new server in replica set mongod --port 30002 --replSet replica_set --dbpath /data/db/rs2 -
dimitardanailov revised this gist
Feb 22, 2016 . No changes.There are no files selected for viewing
-
dimitardanailov revised this gist
Feb 22, 2016 . 2 changed files with 8 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ # Import json mongoimport -d crunchbase -c companies companies.json # Change Storage Engine and Database location. mongod -dbpath WT -storageEngine wiredTiger # Create a new server in replica set mongod --port 30002 --replSet replica_set --dbpath /data/db/rs2 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +0,0 @@ -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 0 additions and 33 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,33 +0,0 @@ -
dimitardanailov revised this gist
Feb 11, 2016 . No changes.There are no files selected for viewing
-
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 33 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ db.companies.aggregate([ { $match: { funding_rounds: { $exists: true, $ne: [] } } }, { $unwind: "$funding_rounds" }, { $sort: { "funding_rounds.funded_year": 1, "funding_rounds.funded_month": 1, "funding_rounds.funded_day": 1 } }, { $group: { _id: { company: "$name" }, first_round: { $first: "$funding_rounds" }, last_round: { $last: "$founding_rounds" }, num_rounds: { $sum: 1 }, total_raised: { $sum: "$funding_rounds.raised_amount" } } }, { $project: { _id: 0, company: "$_id.company", first_round: { amount: "$first_round.raised_amount", article: "$first_round.source_url", year: "$first_round.funded_year" }, last_round: { amount: "$last_round.raised_amount", article: "$last_round.source_url", year: "$first_round.funded_year" }, num_rounds: 1, total_raised: 1 } }, { $sort: { total_raised: -1 } } ]).pretty() -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 0 additions and 33 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,33 +0,0 @@ -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 33 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ db.companies.aggregate([ { $match: { funding_rounds: { $exists: true, $ne: [] } } }, { $unwind: "$funding_rounds" }, { $sort: { "funding_rounds.funded_year": 1, "funding_rounds.funded_month": 1, "funding_rounds.funded_day": 1 } }, { $group: { _id: { company: "$name" }, first_round: { $first: "$funding_rounds" }, last_round: { $last: "$founding_rounds" }, num_rounds: { $sum: 1 }, total_raised: { $sum: "$funding_rounds.raised_amount" } } }, { $project: { _id: 0, company: "$_id.company", first_round: { amount: "$first_round.raised_amount", article: "$first_round.source_url", year: "$first_round.funded_year" }, last_round: { amount: "$last_round.raised_amount", article: "$last_round.source_url", year: "$first_round.funded_year" }, num_rounds: 1, total_raised: 1 } }, { $sort: { total_raised: -1 } } ]).pretty() -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 0 additions and 35 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -146,39 +146,4 @@ db.students.createIndex({ 'scores.score': 1 }); # Unwind > db.companies.aggregate([ { $unwind: "$funding_rounds" }, { $unwind: "$funding_rounds.investments" }, { $match: { "funding_rounds.investments.financial_org.permalink": "greylock" } }, { $project : { _id: 0, name: 1, fundingOrganization: "$funding_rounds.investments.financial_org.permalink" } } , ]) ``` -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -164,6 +164,7 @@ db.companies.aggregate([ total_raised: { $sum: "$funding_rounds.raised_amount" } } }, { $project: { _id: 0, company: "$_id.company", first_round: { amount: "$first_round.raised_amount", -
dimitardanailov revised this gist
Feb 11, 2016 . 2 changed files with 34 additions and 32 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -146,4 +146,38 @@ db.students.createIndex({ 'scores.score': 1 }); # Unwind > db.companies.aggregate([ { $unwind: "$funding_rounds" }, { $unwind: "$funding_rounds.investments" }, { $match: { "funding_rounds.investments.financial_org.permalink": "greylock" } }, { $project : { _id: 0, name: 1, fundingOrganization: "$funding_rounds.investments.financial_org.permalink" } } , ]) # Group db.companies.aggregate([ { $match: { funding_rounds: { $exists: true, $ne: [] } } }, { $unwind: "$funding_rounds" }, { $sort: { "funding_rounds.funded_year": 1, "funding_rounds.funded_month": 1, "funding_rounds.funded_day": 1 } }, { $group: { _id: { company: "$name" }, first_round: { $first: "$funding_rounds" }, last_round: { $last: "$founding_rounds" }, num_rounds: { $sum: 1 }, total_raised: { $sum: "$funding_rounds.raised_amount" } } }, { $project: { company: "$_id.company", first_round: { amount: "$first_round.raised_amount", article: "$first_round.source_url", year: "$first_round.funded_year" }, last_round: { amount: "$last_round.raised_amount", article: "$last_round.source_url", year: "$first_round.funded_year" }, num_rounds: 1, total_raised: 1 } }, { $sort: { total_raised: -1 } } ]).pretty() ``` -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 32 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ db.companies.aggregate([ { $match: { funding_rounds: { $exists: true, $ne: [] } } }, { $unwind: "$funding_rounds" }, { $sort: { "funding_rounds.funded_year": 1, "funding_rounds.funded_month": 1, "funding_rounds.funded_day": 1 } }, { $group: { _id: { company: "$name" }, first_round: { $first: "$funding_rounds" }, last_round: { $last: "$founding_rounds" }, num_rounds: { $sum: 1 }, total_raised: { $sum: "$funding_rounds.raised_amount" } } }, { $project: { company: "$_id.company", first_round: { amount: "$first_round.raised_amount", article: "$first_round.source_url", year: "$first_round.funded_year" }, last_round: { amount: "$last_round.raised_amount", article: "$last_round.source_url", year: "$first_round.funded_year" }, num_rounds: 1, total_raised: 1 } }, { $sort: { total_raised: -1 } } ]).pretty() -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 0 additions and 32 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +0,0 @@ -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,4 +29,4 @@ db.companies.aggregate([ total_raised: 1 } }, { $sort: { total_raised: -1 } } ]).pretty() -
dimitardanailov revised this gist
Feb 11, 2016 . No changes.There are no files selected for viewing
-
dimitardanailov revised this gist
Feb 11, 2016 . No changes.There are no files selected for viewing
-
dimitardanailov revised this gist
Feb 11, 2016 . No changes.There are no files selected for viewing
-
dimitardanailov revised this gist
Feb 11, 2016 . No changes.There are no files selected for viewing
-
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 32 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ db.companies.aggregate([ { $match: { funding_rounds: { $exists: true, $ne: [] } } }, { $unwind: "$funding_rounds" }, { $sort: { "funding_rounds.funded_year": 1, "funding_rounds.funded_month": 1, "funding_rounds.funded_day": 1 } }, { $group: { _id: { company: "$name" }, first_round: { $first: "$funding_rounds" }, last_round: { $last: "$founding_rounds" }, num_rounds: { $sum: 1 }, total_raised: { $sum: "$funding_rounds.raised_amount" } } }, { $project: { company: "$_id.company", first_round: { amount: "$first_round.raised_amount", article: "$first_round.source_url", year: "$first_round.funded_year" }, last_round: { amount: "$last_round.raised_amount", article: "$last_round.source_url", year: "$first_round.funded_year" }, num_rounds: 1, total_raised: 1 } }, { $sort: { total_raised: -1 } } ]).pretty() -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -143,4 +143,7 @@ db.students.createIndex({ 'scores.score': 1 }); # Skip > db.companies.aggregate([ { $match: { founded_year: 2004 } }, { $sort: { name: 1 } }, { $skip: 10 }, { $limit: 5 }, { $project: { _id: 0, name:1, founded_year: 1 } } ]) # Unwind > db.companies.aggregate([ { $unwind: "$funding_rounds" }, { $unwind: "$funding_rounds.investments" }, { $match: { "funding_rounds.investments.financial_org.permalink": "greylock" } }, { $project : { _id: 0, name: 1, fundingOrganization: "$funding_rounds.investments.financial_org.permalink" } } , ]) ``` -
dimitardanailov revised this gist
Feb 11, 2016 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -124,4 +124,23 @@ db.students.createIndex({ 'scores.score': 1 }); > db.getProfilingLevel() > db.setProfilingLevel(1, 4) > db.getProfilingStatus() ``` ```javascript # Aggregation framework # Aggregate operator > db.companies.aggregate([ { $match: { founded_year: 2004 } }, ]) # Projection > db.companies.aggregate([ { $match: { founded_year: 2004 } }, { $project: { _id: 0, name:1, founded_year: 1 } } ]) # Limit > db.companies.aggregate([ { $match: { founded_year: 2004 } }, { $limit: 5 }, { $project: { _id: 0, name:1, founded_year: 1 } } ]) # Sort > db.companies.aggregate([ { $match: { founded_year: 2004 } }, { $sort: { name: 1 } }, { $limit: 5 }, { $project: { _id: 0, name:1, founded_year: 1 } } ]) # Skip > db.companies.aggregate([ { $match: { founded_year: 2004 } }, { $sort: { name: 1 } }, { $skip: 10 }, { $limit: 5 }, { $project: { _id: 0, name:1, founded_year: 1 } } ]) ``` -
dimitardanailov revised this gist
Feb 10, 2016 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -115,4 +115,13 @@ db.students.createIndex({ 'scores.score': 1 }); # Text index > db.sentences.ensureIndex({ 'words': 'text' }) > db.sentences.find({ 'text': { $search: 'dog' } } ) ``` ```javascript # Profiling > db.system.profile.find({ ns: /school.students/}).sort({ts: 1}).pretty() > db.system.profile.find({millis: { $gt: 1 }}).sort({ts: 1}).pretty() > db.getProfilingLevel() > db.setProfilingLevel(1, 4) > db.getProfilingStatus() ``` -
dimitardanailov revised this gist
Feb 10, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -111,4 +111,8 @@ db.students.createIndex({ 'scores.score': 1 }); > db.places.ensureIndex({ location: '2dg' }) # What is the query that will query a collection named "stores" to return the stores that are within 1,000,000 meters of the location latitude=39, longitude=-130? Type the query in the box below. Assume the stores collection has a 2dsphere index on "loc" and please use the "$near" operator > db.stores.find({ loc:{ $near: { $geometry: { type: "Point", coordinates: [-130, 39]}, $maxDistance:1000000 } } }) # Text index > db.sentences.ensureIndex({ 'words': 'text' }) > db.sentences.find({ 'text': { $search: 'dog' } } ) ``` -
dimitardanailov revised this gist
Feb 10, 2016 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -101,4 +101,14 @@ db.students.createIndex({ 'scores.score': 1 }); # Create unique index > db.stuff.createIndex({ thing: 1 }, { unique: true }); # Geospatial Indexes > db.collection.ensureIndex({ location: '2d' }) # Suppose you have a 2D geospatial index defined on the key location in the collection places. Write a query that will find the closest three places (the closest three documents) to the location 74, 140. > db.places.find( { location : { $near : [74,140] } }).limit(3) # Geospatial Spherical > db.places.ensureIndex({ location: '2dg' }) # What is the query that will query a collection named "stores" to return the stores that are within 1,000,000 meters of the location latitude=39, longitude=-130? Type the query in the box below. Assume the stores collection has a 2dsphere index on "loc" and please use the "$near" operator > db.stores.find({ loc:{ $near: { $geometry: { type: "Point", coordinates: [-130, 39]}, $maxDistance:1000000 } } }) ``` -
dimitardanailov revised this gist
Feb 9, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -98,4 +98,7 @@ db.movieDetails.find({ "writters" : ["Joel Coen", "Ethan Coen"] }).count() # Create .not notation index db.students.createIndex({ 'scores.score': 1 }); # Create unique index > db.stuff.createIndex({ thing: 1 }, { unique: true }); ``` -
dimitardanailov revised this gist
Feb 9, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -95,4 +95,7 @@ db.movieDetails.find({ "writters" : ["Joel Coen", "Ethan Coen"] }).count() # Delete index > db.students.dropIndex({ student_id: 1}); # Create .not notation index db.students.createIndex({ 'scores.score': 1 }); ``` -
dimitardanailov revised this gist
Feb 9, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -94,5 +94,5 @@ db.movieDetails.find({ "writters" : ["Joel Coen", "Ethan Coen"] }).count() > db.students.getIndexes(); # Delete index > db.students.dropIndex({ student_id: 1}); ``` -
dimitardanailov revised this gist
Feb 9, 2016 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -88,5 +88,11 @@ db.movieDetails.find({ "writters" : ["Joel Coen", "Ethan Coen"] }).count() > db.students.explain().find({ student: 5 }); # Create a complex index. student_id will be asc, class_id will be desc. > db.students.createIndex({ student_id: 1, class_id: -1 }); # Get collection indexes > db.students.getIndexes(); # Delete index db.students.dropIndex({ student_id: 1}); ``` -
dimitardanailov revised this gist
Feb 9, 2016 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -83,5 +83,10 @@ db.movieDetails.find({ "writters" : ["Joel Coen", "Ethan Coen"] }).count() ```javascript # Create a asc index > db.students.createIndex({ student_id: 1}); # Explain database configurations > db.students.explain().find({ student: 5 }); # Create a complex index. student_id will be asc, class_id will be desc. db.students.createIndex({ student_id: 1, class_id: -1 }); ``` -
dimitardanailov revised this gist
Feb 9, 2016 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -79,4 +79,9 @@ db.movieDetails.find({ "writters" : ["Joel Coen", "Ethan Coen"] }).count() > db.movieDetails.find({ countries: { $size: 1 } }).pretty() > db.movieDetails.find({ boxOffice: { $elemMatch: { country: "UK", revenie: { $gt: 15 } } } }).pretty() ``` ```javascript # Create a asc index db.students.createIndex({ student_id: 1}); ```
NewerOlder