You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.4 KiB

Mongo - Performance

Lesson Objectives

  1. Explain indexes
  2. Explain text indexes
  3. Explain replication
  4. Explain sharding

Explain indexes

  1. db.employees.ensureIndex({name: 1});
  2. db.employees.dropIndex({name: 1});
  3. db.employees.ensureIndex({name: 1}, {unique: true});
  4. indexes on embedded fields
  5. indexes on arrays
  6. db.employees.ensureIndex({name: 1, salary: -1});

Explain text indexes

  1. db.articles.createIndex({ subject : "text", content : "text" })
  2. drop text index
    • db.articles.getIndexes()
    • db.articles.dropIndex('index_name')
  3. db.articles.find( { $text: { $search: "coffee" } } )
  4. db.articles.find( { $text: { $search: "leche", $language: "es" } } )
    • stop words (a, the, and, etc)
  5. db.articles.find( { $text: { $search: "bake coffee cake" } } )
  6. db.articles.find( { $text: { $search: "\"coffee cake\"" } } )
  7. db.articles.find( { $text: { $search: "bake coffee -cake" } } )
  8. db.articles.find( { $text: { $search: "cake" } }, { score: { $meta: "textScore" } } )
db.articles.find(
   { $text: { $search: "cake" } },
   { score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )

Explain replication

  1. Writes sent to secondary DBs asynchonously
  2. Reads can happen on secondaries
    • although data may be stale
  3. If primary goes down, a secondary is chosen to be new primary

Explain sharding

  1. split data across multiple servers