Skip to content

Instantly share code, notes, and snippets.

@demesew
Forked from dimitardanailov/mongo-commands.md
Created January 13, 2021 19:07
Show Gist options
  • Save demesew/90a924dbaa65f6d8c3834cb237a008c1 to your computer and use it in GitHub Desktop.
Save demesew/90a924dbaa65f6d8c3834cb237a008c1 to your computer and use it in GitHub Desktop.

Revisions

  1. @dimitardanailov dimitardanailov revised this gist Mar 2, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions mongo-commands.sh
    Original 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
  2. @dimitardanailov dimitardanailov revised this gist Feb 22, 2016. No changes.
  3. @dimitardanailov dimitardanailov revised this gist Feb 22, 2016. 2 changed files with 8 additions and 5 deletions.
    8 changes: 8 additions & 0 deletions mongo-commands.sh
    Original 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
    5 changes: 0 additions & 5 deletions mongo-import.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    # Import json
    mongoimport -d crunchbase -c companies companies.json

    # Change Storage Engine and Database location.
    mongod -dbpath WT -storageEngine wiredTiger
  4. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 0 additions and 33 deletions.
    33 changes: 0 additions & 33 deletions aggreation-exapmple.js
    Original file line number Diff line number Diff line change
    @@ -1,33 +0,0 @@
    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()
  5. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. No changes.
  6. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 33 additions and 0 deletions.
    33 changes: 33 additions & 0 deletions aggreation-exapmple.js
    Original 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()
  7. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 0 additions and 33 deletions.
    33 changes: 0 additions & 33 deletions group-command.sh
    Original file line number Diff line number Diff line change
    @@ -1,33 +0,0 @@
    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()
  8. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 33 additions and 0 deletions.
    33 changes: 33 additions & 0 deletions group-command.sh
    Original 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()
  9. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 0 additions and 35 deletions.
    35 changes: 0 additions & 35 deletions mongo-commands.md
    Original 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" } } , ])

    # 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: {
    _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()
    ```
  10. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions mongo-commands.md
    Original 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",
  11. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 2 changed files with 34 additions and 32 deletions.
    32 changes: 0 additions & 32 deletions aggreation-exapmple.js
    Original file line number Diff line number Diff line change
    @@ -1,32 +0,0 @@
    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()
    34 changes: 34 additions & 0 deletions mongo-commands.md
    Original 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()
    ```
  12. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions aggreation-exapmple.js
    Original 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()
  13. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 0 additions and 32 deletions.
    32 changes: 0 additions & 32 deletions aggreation-exapmple.js
    Original file line number Diff line number Diff line change
    @@ -1,32 +0,0 @@
    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()
  14. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion aggreation-exapmple.js
    Original file line number Diff line number Diff line change
    @@ -29,4 +29,4 @@ db.companies.aggregate([
    total_raised: 1
    } },
    { $sort: { total_raised: -1 } }
    ]).pretty()
    ]).pretty()
  15. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. No changes.
  16. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. No changes.
  17. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. No changes.
  18. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. No changes.
  19. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions aggreation-exapmple.js
    Original 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()
  20. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions mongo-commands.md
    Original 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" } } , ])
    ```
  21. @dimitardanailov dimitardanailov revised this gist Feb 11, 2016. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions mongo-commands.md
    Original 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 } } ])
    ```
  22. @dimitardanailov dimitardanailov revised this gist Feb 10, 2016. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions mongo-commands.md
    Original 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()
    ```
  23. @dimitardanailov dimitardanailov revised this gist Feb 10, 2016. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions mongo-commands.md
    Original 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' } } )
    ```
  24. @dimitardanailov dimitardanailov revised this gist Feb 10, 2016. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions mongo-commands.md
    Original 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 } } })
    ```
  25. @dimitardanailov dimitardanailov revised this gist Feb 9, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions mongo-commands.md
    Original 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 });
    ```
  26. @dimitardanailov dimitardanailov revised this gist Feb 9, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions mongo-commands.md
    Original 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 });
    ```
  27. @dimitardanailov dimitardanailov revised this gist Feb 9, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mongo-commands.md
    Original 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});
    > db.students.dropIndex({ student_id: 1});
    ```
  28. @dimitardanailov dimitardanailov revised this gist Feb 9, 2016. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion mongo-commands.md
    Original 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 });
    > db.students.createIndex({ student_id: 1, class_id: -1 });

    # Get collection indexes
    > db.students.getIndexes();

    # Delete index
    db.students.dropIndex({ student_id: 1});
    ```
  29. @dimitardanailov dimitardanailov revised this gist Feb 9, 2016. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion mongo-commands.md
    Original 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});
    > 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 });
    ```
  30. @dimitardanailov dimitardanailov revised this gist Feb 9, 2016. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions mongo-commands.md
    Original 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});
    ```