Rendering NumberLong in a single field when using mongosh

37 Views Asked by At

I have a collection c in DB named ftest in MongoDB. A document has been created in that collection with a NumberLong field this way:

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

I get the content of the collection this way (based in this approach):

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

Comparing with how mongo legacy shell works:

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

So:

  • What's the meaning of low, high and unsigned? Are they documented somewhere?
  • Can they be converted to a single field in a similar way mongo legacy shell does?

Thanks!

1

There are 1 best solutions below

0
fgalan On BEST ANSWER

Thanks to @WernfriedDomscheit feedback, using

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

I get

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

which cover perfectly my use case.