面试题答案
一键面试在MongoDB中,可以使用以下代码在books
集合的title
和description
字段上创建文本索引:
db.books.createIndex( { title: "text", description: "text" } )
db.books
:表示操作的集合为books
集合。createIndex
:这是MongoDB提供的创建索引的方法。{ title: "text", description: "text" }
:指定在title
和description
字段上创建文本索引,这里"text"
表示文本索引类型。