查看 MongoDB 文档,您可以确保在应用程序运行时使用如下命令为集合创建索引:
db.myCollection.ensureIndex({'my-col': 1}, {unique: true})
我在反应式 mongo api 中找不到类似的东西。这样的事情存在吗?
查看 MongoDB 文档,您可以确保在应用程序运行时使用如下命令为集合创建索引:
db.myCollection.ensureIndex({'my-col': 1}, {unique: true})
我在反应式 mongo api 中找不到类似的东西。这样的事情存在吗?
截至 libraryDependencies += "org.reactivemongo" %% "play2-reactivemongo" % "0.20.3-play28"
1st定义索引
val createdTSInx = Index(
key = Seq("createdTS" -> IndexType.Ascending),
name = Some("createdTSInx"),
unique = true,
background = false,
sparse = false,
expireAfterSeconds = None,
storageEngine = None,
weights = None,
defaultLanguage = None,
languageOverride = None,
textIndexVersion = None,
sphereIndexVersion = None,
bits = None,
min = None,
max = None,
bucketSize = None,
collation = None,
wildcardProjection = None,
version = None,
partialFilter = None,
options = BSONDocument.empty)
// 创造
collection.indexesManager.create(createdTSInx)
//确保
collection.indexesManager.ensure(createdTSInx)