Raven DB 计数查询
我需要获取特定集合中的文档计数:
有一个现有索引 Raven/DocumentCollections,它存储与属于该集合的实际文档配对的集合的计数和名称。如果可能的话,我想从这个索引中获取计数。
这是 Raven/DocumentCollections 索引的 Map-Reduce:
from doc in docs
let Name = doc["@metadata"]["Raven-Entity-Name"]
where Name != null
select new { Name , Count = 1}
from result in results
group result by result.Name into g
select new { Name = g.Key, Count = g.Sum(x=>x.Count) }
顺便说一下,var Count = DocumentSession.Query
总是返回 0 作为我的结果,尽管我的数据库中显然有 500 个奇怪的文档,但其中至少有 50 个在其元数据中将“Raven-Entity-Name”作为“Posts”。我完全不知道为什么这个 Count 查询不断返回 0 作为答案 - Raven 日志在 Count 完成时显示这一点
Request # 106: GET - 0 ms - TestStore - 200 - /indexes/dynamic/Posts?query=&start=0&pageSize=1&aggregation=None
I have a need to get a Count of Documents in a particular collection :
There is an existing index Raven/DocumentCollections that stores the Count and Name of the collection paired with the actual documents belonging to the collection. I'd like to pick up the count from this index if possible.
Here is the Map-Reduce of the Raven/DocumentCollections index :
from doc in docs
let Name = doc["@metadata"]["Raven-Entity-Name"]
where Name != null
select new { Name , Count = 1}
from result in results
group result by result.Name into g
select new { Name = g.Key, Count = g.Sum(x=>x.Count) }
On a side note, var Count = DocumentSession.Query<Post>().Count();
always returns 0 as the result for me, even though clearly there are 500 odd documents in my DB atleast 50 of them have in their metadata "Raven-Entity-Name" as "Posts". I have absolutely no idea why this Count query keeps returning 0 as the answer - Raven logs show this when Count is done
Request # 106: GET - 0 ms - TestStore - 200 - /indexes/dynamic/Posts?query=&start=0&pageSize=1&aggregation=None
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于任何仍在寻找答案的人(这个问题于 2011 年发布),现在正确的方法是:
For anyone still looking for the answer (this question was posted in 2011), the appropriate way to do this now is:
要从索引中获取结果,您可以使用:
这将为您提供您想要的结果。
To get the results from the index, you can use:
That will give you the result you want.