Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-20

Query for timestamp has inconsistent behavior

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      When inserting a document with a property of value Timestamp() and this is queried, then this works fine.

      However, if the dataset contains a second document with a property of Date(), completely unrelated to the first document, and a query for Timestamp() is issued, the driver errors out.

      The following code shows the error case. If you comment out the document with the Date() property, the query works on the single document.

      var Db = require('mongodb').Db,
      Server = require('mongodb').Server,
      ObjectID = require('mongodb').ObjectID,
      Binary = require('mongodb').Binary,
      GridStore = require('mongodb').GridStore,
      Code = require('mongodb').Code,
      BSON = require('mongodb').pure().BSON,
      assert = require('assert'),
      MongoDB = require('mongodb');

      var db = new Db('jiras', new Server("127.0.0.1", 27017,

      {auto_reconnect: false, poolSize: 4}

      ),

      {w: 0, native_parser: false}

      );

      db.open(function (err, db) {
      db.dropCollection("timestamp", function (err, result) {

      db.createCollection('timestamp', function (err, collection) {
      if (err)

      { console.log(err); }

      var timestampDocument =

      {"x": new MongoDB.Timestamp(1, 2), "comment": "Timestamp(1,2)"}

      ;
      var dateDocument =

      {"x": new Date("2012-08-31 12:13:14:156 UTC"), "comment": "2012-08-31 12:13:14:156 UTC"}

      ;
      console.log("original document:");
      console.log(timestampDocument);
      console.log(dateDocument);

      collection.insert([timestampDocument, dateDocument],

      {w: 1}

      , function (err, result) {
      var timestampQuery =

      {"x": new MongoDB.Timestamp(1, 2)}

      ;
      var cursor;
      var cursorStream;

      assert.equal(null, err);

      cursor = collection.find(timestampQuery);
      cursorStream = cursor.stream();
      cursorStream.on("data", function (docs)

      { console.log("query:"); console.log(timestampQuery); console.log("result document:"); console.log(docs); }

      );
      cursorStream.on("close", function ()

      { db.close(); }

      );
      cursorStream.on("error", function (err)

      { console.log(err); }

      );
      });
      });
      });
      });

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            chris@real-programmer.com Christoph Bussler
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: