mongodb 查询的坑

如果在mongodb中find的字段也是一个json,就会有顺序问题。

比如db.collections.find({ 'params': {'ao_ma2': 666, 'ao_ma1': 34}, 'ts': 1604908800} 和db.collections.find({ 'params': {'ao_ma1': 34, 'ao_ma2': 666,}, 'ts': 1604908800}结果并不一样

这个时候推荐的方式是拆开来:db.collections.find({ 'params.ao_ma1':34, 'params.ao_ma2': 666, 'ts': 1604908800},用逗号的子查询可以保证得到正确的结果

posted @ 2020-11-09 18:31  hyfwin  阅读(140)  评论(0编辑  收藏  举报