데이터베이스 첫걸음

Scope: MongoDB indexes are general-purpose indexes used for a wide range of query optimizations. In contrast, MongoDB Atlas Search indexes are specialized for full-text search and related functionalities.

Index in MongoDB : used for efficient execution for the query by limiting the number of documents getting scanned for the inspect.

Search Index

Atlas Search : Leverages the power of Apache Lucene to enable full text search indexes for your data.

  1. Data Preparation: Assume you have a collection named articles in your MongoDB database with documents that look like this:
{
  "title": "Learning MongoDB",
  "content": "MongoDB is a NoSQL database that offers high performance...",
  "tags": ["database", "NoSQL", "MongoDB"]
}
  1. Create a Search Index: In the MongoDB Atlas UI, go to your cluster and then:
  1. Querying Using the Search Index
db.articles.aggregate([
  {
    $search: {
      "text": {
        "query": "high performance",
        "path": "content" // Search in the 'content' field
      }
    }
  },
  {
    $limit: 10 // Limit to the first 10 results
  }
])
{
  $search: {
    "compound": {
      "must": [
        {
          "text": {
            "query": "MongoDB",
            "path": "title"
          }
        }
      ],
      "should": [
        {
          "text": {
            "query": "NoSQL",
            "path": "tags"
          }
        }
      ]
    }
  }
}

STORAGE SIZE: 9.79GB LOGICAL DATA SIZE: 36.59GB TOTAL DOCUMENTS: 51027194 INDEXES TOTAL SIZE: 2.66GB