Meteor 似乎缺少 $max 更新运算符。
我正在关注文档 here在 meteor mongo shell 中:
meteor:PRIMARY> db.vesrion()
2.4.9
meteor:PRIMARY> db.scores.insert({ _id: 1, highScore: 800, lowScore: 200 })
meteor:PRIMARY> db.scores.find()
{ "_id" : 1, "highScore" : 800, "lowScore" : 200 }
meteor:PRIMARY> db.scores.update( { _id: 1 }, { $max: { highScore: 950 } } )
Invalid modifier specified $max
我是不是做错了什么?我可以通过在更新条件中添加 $lt 子句来模拟 $max 行为,但是如果我还想更新其他字段(例如,在更新 highScore 的同时将 numGamesPlayed 增加 1),它会很笨重并且无法正常工作。
最佳答案
你没有做错什么,问题是 $max
更新运算符是在 2.6 中添加的。
如果您单击该文档页面左上角的 2.6(当前)
并选择版本 2.4 文档,您将看到 $max
不存在。
我能找到的最好的引用是 2.6 release notes .
关于Meteor 中的 MongoDB 缺少 $max 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25518796/