84669 人が学習中
152542 人が学習中
20005 人が学習中
5487 人が学習中
7821 人が学習中
359900 人が学習中
3350 人が学習中
180660 人が学習中
48569 人が学習中
18603 人が学習中
40936 人が学習中
1549 人が学習中
1183 人が学習中
32909 人が学習中
大家好,我是mongodb新人。我现在有一个Post Collection, 里面有created_at字段和creator字段,我现在想如下查询
db.posts.find({"creator" : ObjectId("xxxxx") }).sort("-created_at").limit(10)
结果我发现数据库遍历了我所有的post。 无论什么用户都是遍历所有post。我已经给created_at索引了。 我自己觉得应该只要搜索部分数据库就能返回结果了。 请问是我哪里出了问题?
谢谢!
欢迎选择我的课程,让我们一起见证您的进步~~
db.posts.find({"creator" : ObjectId("xxxxx") }).sort("created_at:-1").limit(10)
简单地回答:
db.posts.createIndex({creator: 1, created_at: -1})
你需要了解索引相关的知识和如何使用explain来了解性能问题。
简单地回答:
你需要了解索引相关的知识和如何使用explain来了解性能问题。