[SERVER-2684] special types in shell (e.g. Timestamp) display in variety of ways, and can confuse users Created: 04/Mar/11  Updated: 12/Jul/16  Resolved: 07/Oct/11

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 2.1.0

Type: Improvement Priority: Trivial - P5
Reporter: Scott Hernandez (Inactive) Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DOCS-584 Release notes for 2.2 should mention ... Closed
related to JAVA-280 BSONTimestamp and some other fields a... Closed
related to DOCS-586 Document "str" property of ObjectId()... Closed
is related to SERVER-7055 ObjectId to String type conversion di... Closed
is related to DOCS-563 documentation for valueOf() and toStr... Closed
is related to SERVER-6986 ObjectId#toString and ObjectId#valueOf Closed
Backwards Compatibility: Major Change
Participants:

 Description   

The way a timestamp prints in the shell is misleading and makes it look like an embedded doc which is not true.

If currently prints as: {ts:{t:#, i:#}}

But you cannot do this: find(

{"ts.t": #}

) or this: find({ts: {t:#, i:#}}) ; you must do this find(

{ts: new Timestamp(#, #)}

)



 Comments   
Comment by auto [ 13/Oct/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: - SERVER-2684: V8 was still expecting old toString() for a dbref
Branch: master
https://github.com/mongodb/mongo/commit/8631cd3aa42c3c3be15c231aac752b3a5976a3ea

Comment by auto [ 10/Oct/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: - SERVER-2684: csv export expects its own special output for ObjectId
Branch: master
https://github.com/mongodb/mongo/commit/e3294065ef9a0aa5250ce00817cc228037a47f4b

Comment by Antoine Girbal [ 07/Oct/11 ]

ObjectId:
old tojson: ObjectId("4e8f8ca468249caa40cb1bb8")
old tostring: 4e8f8ca468249caa40cb1bb8
new: ObjectId("4e8f730460beab88c1882f5e")

DBRef:
old tojson:

{ "$ref" : "test", "$id" : "theid" }

old tostring:

{ "$ref" : "test", "$id" : "theid" }

new: DBRef("test", "theid")

DBPointer:
old tojson:

{ "ns" : "test", "id" : ObjectId("4e8f8ca468249caa40cb1bb9") }

old tostring: DBPointer test:4e8f8ca468249caa40cb1bb9
new: DBPointer("test", ObjectId("4e8f730460beab88c1882f5f"))

Timestamp:
old tojson:

{ "t" : 10, "i" : 20 }

old tostring: [object Timestamp]
new: Timestamp(10, 20)

BinData:
old tojson: BinData(3,"VQ6EAOKbQdSnFkRmVUQAAA==")
old tostring: BinData(3,"VQ6EAOKbQdSnFkRmVUQAAA==")
new: BinData(3,"VQ6EAOKbQdSnFkRmVUQAAA==")

UUID:
old tojson: BinData(3,"VQ6EAOKbQdSnFkRmVUQAAA==")
old tostring: BinData(3,"VQ6EAOKbQdSnFkRmVUQAAA==")
new: BinData(3,"VQ6EAOKbQdSnFkRmVUQAAA==")

MD5:
old tojson: BinData(5,"VQ6EAOKbQdSnFkRmVUQAAA==")
old tostring: BinData(5,"VQ6EAOKbQdSnFkRmVUQAAA==")
new: BinData(5,"VQ6EAOKbQdSnFkRmVUQAAA==")

HexData:
old tojson: BinData(4,"VQ6EAOKbQdSnFkRmVUQAAA==")
old tostring: BinData(4,"VQ6EAOKbQdSnFkRmVUQAAA==")
new: BinData(4,"VQ6EAOKbQdSnFkRmVUQAAA==")

NumberLong:
old tojson: NumberLong(100)
old tostring: NumberLong(100)
new: NumberLong(100)

NumberInt:
old tojson: 100
old tostring: NumberInt(100)
new: NumberInt(100)

Comment by auto [ 07/Oct/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: - SERVER-2684: v8 was relying on oid.toString() during conversion
Branch: master
https://github.com/mongodb/mongo/commit/fccf1190d8ad44e553e80938916bcd111d95b9a4

Comment by auto [ 07/Oct/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: - SERVER-2684: special types in shell (e.g. Timestamp) display in variety of ways, and can confuse users
Branch: master
https://github.com/mongodb/mongo/commit/a6bfe265732c01c7ea2626b6889dbc9bba6918ca

Comment by Antoine Girbal [ 07/Oct/11 ]

Tried to bring some unity and move toString from C++ to common utils.js.
The idea is that tojson() and toString() should have same output, which is a string that basically represents the constructor.

ObjectId("4e8f730460beab88c1882f5e")
DBRef("test", "theid")
DBPointer("test", ObjectId("4e8f730460beab88c1882f5f"))
Timestamp(10, 20)
BinData(3,"VQ6EAOKbQdSnFkRmVUQAAA==")
UUID -> BinData(3,"VQ6EAOKbQdSnFkRmVUQAAA==")
MD5 -> BinData(5,"VQ6EAOKbQdSnFkRmVUQAAA==")
HexData -> BinData(4,"VQ6EAOKbQdSnFkRmVUQAAA==")
NumberLong(100)
NumberInt(100)

Let me know if the fact that output changed may be a problem for other components.
One sensitive point may be that now ObjectId outputs ObjectId("4e8f730460beab88c1882f5e") instead of 4e8f730460beab88c1882f5e
All tests passed besides jstests/objid7.js which expected hardcoded old output.

Ideally in the future we will add a method toRealJson() that outputs a true parseable JSON format, same way as Java driver, to fix import/export.

Generated at Thu Feb 08 03:00:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.