MongoDB Norm query nested objects

萝らか妹 提交于 2019-12-05 00:51:40

问题


Does anyone have a sample of how to query for nested/inner objects in MongoDB using NORM (C#)? For example, if a typical document in a collection looks like Order/OrderItems, how can I look up a specific OrderItem by OrderItem.Quantity > 10.


回答1:


Typing this from memory, so sorry if it's wildly wrong:

using ( var session = new MongoSession<Order>( DbName ) )
{
    var orders = session.Queryable
                .Where( o => o.OrderItems.Any( oi => oi.Quantity > 10 ) )
                .ToList();
}



回答2:


You need to create extra field 'size', that you increment when add new items, and query on it.



来源:https://stackoverflow.com/questions/2900763/mongodb-norm-query-nested-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!