使用java代码在mongoDB中创建复合索引(多个字段)

时间:2017-05-21 12:53:51

标签: java mongodb

public void createCompositeIndex(MongoClient mongo) {
    Document index = new Document("id_click", 1).append("id_address", 1);
    MongoCollection<Document> collection = mongo.getDatabase("db").getCollection("Collection");
    collection.createIndex(index, new IndexOptions());
}

1 个答案:

答案 0 :(得分:0)

来自official examples for the MongoDB Java Driver 3.4

where data @> '{"id":1884595530}'::jsonb