在Robomongo中将包含日期的文档插入集合中

Lar*_*ard 8 mongodb robo3t

我正在与Robomongo合作,我手动插入一个对象.

我想在我的对象上有一个字段,这是当前日期.通常我习惯Date.now()在Javascript中使用.但是,当我在Robomongo工具中使用插入文档表单时,我得到:

Unable to parse JSON:
Expecting '(', at (4, 15).
Run Code Online (Sandbox Code Playgroud)

示例JSON:

{
    serial: '1231323123',
    game: 'World of Warcraft',
    date: Date.now()
}
Run Code Online (Sandbox Code Playgroud)

知道如何插入此记录吗?

Ste*_*nie 5

如果您将它直接插入到Robomongo 0.8.4 shell提示符中,例如进入game集合,您的示例就可以正常工作:

db.game.insert({
    serial: '1231323123',
    game: 'World of Warcraft',
    date: Date.now()
})
Run Code Online (Sandbox Code Playgroud)

如果使用上下文菜单(Insert Document...),JSON解析器将返回您遇到的语法错误.

这里的问题是JSON验证目前使用的是一个非MongoDB特有的库.由于多种原因(不带引号的键和未加引号的函数值),上面的JSON 无效,但是在shell中插入有效的mongo.

我为此创建了Robomongo 问题#619.相关的JSON验证差异是问题#448.

在修复JSON验证错误之前,我建议通过Robomongo中的shell提示插入这样的文档.


Lix*_*Lix 3

不幸的是,在现阶段不可能做到这一点,如以下 github 问题中所述:

https://github.com/paralect/robomongo/issues/477

...Robomongo 的 JavaScript 引擎和 mongo shell 2.4+ 中默认的 v8 引擎之间存在一些差异。


问题 #520应该通过将 Robomongo 附带的内置 shell 从 SpiderMonkey 更新到 v8(MongoDB 2.4+ 中的默认值)来解决该问题。