Meteor 中的 MongoDB 缺少 $max 运算符

标签 mongodb meteor

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/

相关文章:

css - 如何在 METEOR 中指定特定的 css 文件

javascript - 当 Router.route(uri, {name : templateName })

javascript - 始终在列表中选择一个 <li>

node.js - 如何发送批量 MongoDB count() 查询?

Mongodb - 聚合函数嵌套ob

c# - MongoDB C# 连接更新对象

javascript - api调用返回undefined后的Meteor方法

http - 内容长度为 0 且响应为 302 的 Meteor HTTP 空白正文

c# - 如果字段为空,如何不在 mongodb 中插入字段?

node.js - MongoDB:子数组的更新属性只更新第一个元素