在mongosh 中
% mongosh
Current Mongosh Log ID: 630639411fcf560da1e8d627
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.4
Using MongoDB: 6.0.1
Using Mongosh: 1.5.4
我得到错误
test> printjsononline({teste : 1})
ReferenceError: printjsononline is not defined
但在升级为mongosh
之前,它曾在mongo
工具中工作。这个功能是什么?如何更换?这由emacs模式使用(http://github.com/own-pt/sensetion.el)我需要使用的。
在新mongosh
中删除的大多数函数都是由Github中的mongosh snippets包提供的。
load('mongonative.js');
load('mongoassert.js');
load('mongotypes.js');
或者编写自己的函数:
if (typeof tojsononeline == 'undefined') {
function tojsononeline(x) {
return EJSON.stringify(x)
.replace(/{"$date":"(.{19,23}Z)"}/g, "ISODate("$1")")
.replace(/{"$oid":"(w{24})"}/g, "ObjectId("$1")")
.replace(/{"$numberDecimal":"(.+?)"}/g, "Decimal128("$1")");
}
}
如Mongosh
文档中所述:
mongosh supports a subset of the mongo shell methods.
Achieving feature parity between mongosh and the mongo shell is an ongoing
effort.
我认为还没有添加对printjsononline
的支持。但是,您可以尝试mongosh
的printjson
方法,如果它同样有效的话。
查看此列表以查找mongosh支持的所有方法。