:インデックスの
他の種類は、そのAPIを介してサポートされています。次に例を示します。
index := Index{
Key: []string{"$2d:loc"},
Bits: 26,
}
err := collection.EnsureIndex(index)
上記の例では、「LOC」フィールドの「2D」インデックスの作成を依頼します。以下に示すように
だから基本的に、あなたは、フォーマット$<indexType>:<indexedField>
を持っている:
package main
import mgo "gopkg.in/mgo.v2"
const (
db = "so_hashed_idx"
coll = "testcoll"
)
func main() {
var s *mgo.Session
var err error
if s, err = mgo.Dial("127.0.0.1:27017"); err != nil {
panic(err)
}
// An index spec is nothing more than a fancy word for the keys
// or the key/value pairs handed over to the Key slice of the
// Index type.
idx := mgo.Index{
Key: []string{"$hashed:_id"},
}
if err := s.DB(db).C(coll).EnsureIndex(idx); err != nil {
panic(err)
}
}
ビルと
> db.testcoll.getIndices()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "so_hashed_idx.testcoll"
},
{
"v" : 1,
"key" : {
"_id" : "hashed"
},
"name" : "_id_hashed",
"ns" : "so_hashed_idx.testcoll"
}
]
私は残りの人生でビールが必要です。 ;)私はお金を節約する。これまでに何を試しましたか? –
@ markus-w-mahlberg私はrunCommandを使ってみましたが、 "index specs"のリストを必要とする "createIndexes"コマンドしかありません。そして私はそれが何であるか分かりません。 – Mohsenasm