使用 mongosh 时在单个字段中渲染 NumberLong

问题描述 投票:0回答:1

我在数据库中有一个集合

c
,在 MongoDB 中名为
ftest
。已在该集合中创建一个带有 NumberLong 字段的文档,如下所示:

db.c.insert({x: NumberLong("1")})

我通过这种方式获取集合的内容(基于这种方法):

$ mongosh mongodb://localhost:27017/ftest --eval 'JSON.stringify(db.c.find().toArray(), null, " ")' --quiet
[
 {
  "_id": "6580316ed1c208e8c6059954",
  "x": {
   "low": 1,
   "high": 0,
   "unsigned": false
  }
 }
]

与 mongo 旧版 shell 的工作方式比较:

$ mongo mongodb://localhost:27017/ftest --eval 'JSON.stringify(db.c.find().toArray(), null, " ")' --quiet
[
 {
  "_id": {
   "$oid": "6580316ed1c208e8c6059954"
  },
  "x": {
   "$numberLong": "1"
  }
 }
]

所以:

  • low
    high
    unsigned
    是什么意思?它们是否记录在某处?
  • 它们可以像 mongo Legacy shell 那样转换为单个字段吗?

谢谢!

mongodb mongo-shell mongosh
1个回答
0
投票

感谢@WernfriedDomscheit 反馈,使用

$ mongosh mongodb://localhost:27017/ftest --eval 'EJSON.stringify(db.c.find().toArray(), null, " ")' --quiet

我明白了

[
 {
  "_id": {
   "$oid": "6580316ed1c208e8c6059954"
  },
  "x": 1
 }
]

完美涵盖了我的用例。

© www.soinside.com 2019 - 2024. All rights reserved.