1、数组某个字段大于
db.collections.find({"backtest_trade_detail":{"$elemMatch":{"sell_stock_nums":{$gte:60}}}})
2、数组某个字段正则表达式
db.collections.find({"buy_strategy_index":{"$elemMatch":{"index_name":/KDJ/}}})
3、数组排序,某个字段取最大值 最小值
db.collections.aggregate( [
{ "$unwind" :"$backtest_trade_detail"},{ "$group": { "_id": "$_id", "value": {"$max":"$backtest_trade_detail.sell_stock_nums" } } },
{ $match : { value : { $gt : 70, $lte : 90 } } }
] );
4、正则表达式
可以匹配出下面:
"filter_type" : "cqfz;fz;gpltsz;rsi;sylt;"
"filter_type" : "fz;gpltsz;rsi;sylt;"
可以排除下面:
"filter_type" : "cqfz;gpltsz;rsi;sylt;"
db.collections.find({"filter_type":{$regex:"([A-Za-z0-9]+[;])+(fz;gpltsz;)+|(^fz;gpltsz;)+"}},{"filter_type":1})