Database Reference
In-Depth Information
When this document is more than 2,419,200 seconds older than the current system time, it will be deleted. You
could test by creating a document more than 2,419,200 seconds old using the following syntax:
date = new Date(new Date().getTime()-2419200000);
db.comments.insert({ "author" : test", "body" : "foo", "ts" : date, "tags" : [] });
Now simply wait a minute and the document should be deleted.
When you set a ttL index, mongoDB sets the usePowerOf2Sizes flag on the given collection. this will
standardize the storage space for each document. this allows the spaces to be reused more effectively by future
documents after they have been deleted.
Note
Text Search Indexes
MongoDB 2.4 introduced a new type of index—text indexes, which allow you to perform full text searches! Chapter 8
discussed the text index feature in detail, but it's worth a quick summary here as we look at optimization. Text search
has long been a desired feature in MongoDB, as it allows you to search for specific words or text within a large text
block. The best example of how text search is relevant is a search feature on the body text of blog posts. This kind
of search would allow you to look for words or phrases within one text field (like the body) or more (like body and
comments) text fields of a document. So to create a text index we run the following command:
>db.posts.ensureIndex( { body: "text" } )
a text search is case-insensitive, meaning it will ignore case; “mongoDB” and “mongodb” are considered the
same text.
Note
Now we can search using our text index with the text command. To do this, we use the runCommand syntax to use
the text command and provide it a value to search:
>db.posts.runCommand( "text", { search: "MongoDB" } )
The results of your text search will be returned to you in order of relevance.
Warning
mongoDB text search is still relatively new and is undergoing rapid evolution.
Dropping an Index
You can elect to drop all indexes or just one specific index from a collection. Use the following function to remove all
indexes from a collection:
>db.posts.dropIndexes()
 
 
Search WWH ::




Custom Search