MongoDB Norm query nested objects

2019-03-31 03:16发布

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.

标签: c# mongodb norm
2条回答
Root(大扎)
2楼-- · 2019-03-31 04:00

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();
}
查看更多
Root(大扎)
3楼-- · 2019-03-31 04:18

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

查看更多
登录 后发表回答