是否可以在记录中使用ensureindex而不是整个集合。Mongodb - ensureindex备案
例如:我的数据库结构
{ "_id" : "com.android.hello",
"rating" : [
[ { "user" : "BBFE7F461E10BEE10A92784EFDB", "value" : "4" } ],
[ { "user" : "BBFE7F461E10BEE10A92784EFDB", "value" : "4" } ]
]
}
这是一个评级系统,我不希望用户在同一个应用程序(com.android.hello)率多次。如果我在user
字段上使用ensureindex,那么用户只能对一个应用程序投票。当我尝试投票完全不同的应用程序(com.android.hi)时,它说重复的密钥。