如何从 Raven DB 中的嵌套集合中查询项目?
我有以下 2 个实体模型:
public class Store : IModel
{
public string Id { get; set; }
public string Name { get; set; }
public string MainPageUrl { get; set; }
public ICollection<Product> Products { get; set; }
}
public class Product : IModel {
public string Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public DateTime Created { get; set; }
}
其中 Store 是我的 Raven Db 中的文档。 我需要创建一个索引,可以在其中按名称查询产品,结果应该是仅包含匹配产品的部分商店文档。
因此,具体来说,我需要询问 Raven Db:哪些商店有包含此文本的产品,以及每个商店中的这些产品是什么。
现在我可以创建一个索引,它为我提供具有匹配产品的存储文档,但它总是为我提供这些文档中的所有产品。
我认为这是一个非常容易回答的问题,但作为 Raven Db 和文档数据库的新手,我无法完成这项工作。
有一个几乎重复的问题 已经在这里了,但我仍然无法使查询/索引工作。
I have following 2 entity models:
public class Store : IModel
{
public string Id { get; set; }
public string Name { get; set; }
public string MainPageUrl { get; set; }
public ICollection<Product> Products { get; set; }
}
public class Product : IModel {
public string Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public DateTime Created { get; set; }
}
and of these Store is a document in my Raven Db.
I need to create an index where I can query products by Name and the result should be partial Store documents containing only matching products.
So to be specific I need to ask Raven Db this: What stores have products containing this text, and what are those products in each store.
Now I can make an index which gives me Store documents with matching products but it always gives me ALL the products in those documents.
I suppose this is a real easy one to answer but being new to Raven Db and document databases I just couldn't make this work.
There is an almost duplicate question here already but I still could not make the query/index work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
骡子,
预计模型中的商店文档包含其所有产品,如果您请求商店文档,您将获得完整商店文档。
如果您只想获取所需内容的投影,则可以使用以下索引:
将名称、价格、创建和 ID 标记为已存储。
然后发出以下查询。
这只会为您提供匹配的产品。
Mule,
That is expected, a Store Document in your model contains all its products, and if you are asking for a Store Document, you'll get the full Store Document.
If you want to just get a projection back for just the things that you want, you can use the following index:
Mark Name, Price, Created and Id as stored.
Then issue the following query.
That will give you only the matching products.