Bug #93839 JavaScript Date values are converted to empty objects in new documents
Submitted: 7 Jan 15:33 Modified: 25 Feb 23:38
Reporter: Rui Quelhas Email Updates:
Status: Closed Impact on me:
None 
Category:Connector for Node.js Severity:S3 (Non-critical)
Version:8.0.13 OS:Any
Assigned to: Rui Quelhas CPU Architecture:Any
Tags: collectionadd, conversion, date, docstore

[7 Jan 15:33] Rui Quelhas
Description:
As a user, I expect to be able to insert documents containing JavaScript Date values into a given collection. Those values need to be converted somehow to something that is supported by the JSON data type, such as an ISO string (similar to what happens when calling JSON.stringify()).

However, right now, those Date values are being converted into empty objects, which is not helpful.

How to repeat:
Assuming there is a `mySchema.myCollection` available:

mysqlx.getSession(config)
  .then(session => {
    var collection = session.getSchema('mySchema').getCollection('myCollection')
    return collection.add({ _id: '1', name: 'foo', createdAt: new Date() })
      .execute()
      .then(() => {
        return collection.find()
          .execute(console.log) // { _id: '1', name: 'foo', createdAt: {} }
      })
  }) 

Suggested fix:
Apply the same conversion rules used by JSON.stringify() when encoding Mysqlx.Crud.Insert operation.
[25 Feb 23:38] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/Node.js 8.0.16 release, and here's the changelog entry:

Date values in documents were converted to empty objects when inserted
into a collection.

Thank you for the bug report.