[英]How do i get this function equivalent in MongoDB, faster? WHERE clause?
i want to know how to query like MYSQL in java this function equivalent: SELECT nick FROM profiles WHERE uuid = 'something';
i want to know how to query like MYSQL in java this function equivalent:
SELECT nick FROM profiles WHERE uuid = 'something';
i have done something like that in my project but it seens too slow and its returning the whole document of the profile requested, unless i use document.get("nick") i get exactly what i want, i'm sorry but i'm really new to MongoDB and i haven't already founded something about this, everything that i found it doesn't really helped me so much..我在我的项目中做过类似的事情,但它看起来太慢了,并且它返回了所请求的配置文件的整个文档,除非我使用 document.get("nick") 我得到了我想要的,对不起,但我我对 MongoDB 真的很陌生,我还没有为此建立一些东西,我发现它并没有真正帮助我太多..
this is the code:这是代码:
FindIterable<Document> results = Main.getCollection(Main.getDatabase(plugin.database), plugin.collection).find(Document.parse("{ uid: '00000000-0000-0000-0009-01fbbfda08e8' }, { nick: 1 }"));
Document document = results.first();
if(document.get("nick") != player.getName()) {
System.out.println("do something");
}
by document var from FindIterable it returns the whole document, but i just want to return the nick of that profile, which the uuid is "00000000-0000-0000-0009-01fbbfda08e8" so i dont need to use document.get and it will be much better for performance, if thats possible.. (sorry for bad english)通过 FindIterable 中的文档 var 它返回整个文档,但我只想返回该配置文件的昵称,其 uuid 为“00000000-0000-0000-0009-01fbbfda08e8”所以我不需要使用 document.get 它会如果可能的话,性能要好得多..(抱歉英语不好)
I suggest you to take a look at how indexes and covered queries work (projections), creating an index for a specific fields would improve your performance for those common queries, and projections would help you to get only the fields you need.我建议您查看索引和覆盖查询的工作方式(投影),为特定字段创建索引将提高您对那些常见查询的性能,而投影将帮助您仅获取所需的字段。
There are plenty of examples (in java also) https://docs.mongodb.com/manual/indexes/#covered-queries有很多例子(在java中)
Here there is an example of exactly what you are asking for: https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/这里有一个您所要求的示例: https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/
Field projection applied on your example:应用于您的示例的现场投影:
.find(eq("uid", "00000000-0000-0000-0009-01fbbfda08e8")).projection(fields(include("nick"), excludeId()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.