gpt4 book ai didi

mongodb - 使用 Java 将权重分配给 MongoDB 中的外部值

转载 作者:可可西里 更新时间:2023-11-01 10:04:14 25 4
gpt4 key购买 nike

这就是我如何在 Mongo Shell 中创建具有不同权重的索引。

             db.blog.ensureIndex(
{
content: "text",
keywords: "text",
about: "text"
},
{
weights: {
content: 10,
keywords: 5,
},
name: "TextIndex"
}
)

这就是我使用 Java 为字段创建索引的方式。

    BasicDBObject index = new BasicDBObject();
index.put("content", "text");
index.put("keywords", "text");
index.put("about", "text");

collection.ensureIndex( index, "TextIndex");

如何使用 Java 驱动程序分配权重?

最佳答案

Java 为索引字段分配权重:

    BasicDBObject index = new BasicDBObject();
index.put("content", "text");
index.put("keywords", "text");
index.put("about", "text");
BasicDBObject weights = new BasicDBObject("content", 10).append("keyword", 5);
BasicDBObject options = new BasicDBObject("weights", weights).append("name", "TextIndex");
collection.createIndex(index,options);

关于mongodb - 使用 Java 将权重分配给 MongoDB 中的外部值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24632740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com