Raven 数据库计数查询 [英] Raven DB Count Queries

查看:34
本文介绍了Raven 数据库计数查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取特定集合中的文档计数:

I have a need to get a Count of Documents in a particular collection :

现有索引 Raven/DocumentCollections 存储集合的计数和名称,并与属于该集合的实际文档配对.如果可能,我想从该索引中获取计数.

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.

这是 Raven/DocumentCollections 索引的 Map-Reduce :

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) }

附带说明,var Count = DocumentSession.Query().Count(); 总是返回 0 作为我的结果,即使我的文件中有 500 个奇怪的文档DB 至少有 50 个在他们的元数据中将Raven-Entity-Name"作为Posts".我完全不知道为什么这个 Count 查询总是返回 0 作为答案——当 Count 完成时,Raven 日志会显示这一点

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

推荐答案

要从索引中获取结果,可以使用:

To get the results from the index, you can use:

session.Query<Collection>("Raven/DocumentCollections")
       .Where(x=>x.Name == "Posts")
       .FirstOrDefault();

这会给你想要的结果.

这篇关于Raven 数据库计数查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆