Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31317

createView is interpreting Date object at creation time

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.4.9
    • Component/s: Aggregation Framework
    • None
    • ALL

      To get the last documents based on their datetime property we can use:

      db.lightningsStrikes.find({ datetime: { $gte: new Date(new Date() - 1000*60*20) } })
      

      The command above gets lightning strikes of last twenty minutes.
      To create a view of it we should to be able to do this: right?

      db.createView("lastLightningStrikes", "lightningStrikes", [{
          $match: {
              datetime: {
                  $gte: new Date(new Date() - 1000*60*20)
              }
          }
      }])
      

      But createView is interpreting new Date() at creation time instead of querying time, as below:

      db.system.views.find().pretty()
      
      {
      	"_id" : "lightning.latestLightningStrikes",
      	"viewOn" : "lightningStrikes",
      	"pipeline" : [
      		{
      			"$match" : {
      				"datetime" : {
      					"$gte" : ISODate("2017-09-28T19:25:34.410Z")
      				}
      			}
      		}
      	]
      }
      

      I suppose that it should be as below:

      {
      	"_id" : "lightning.latestLightningStrikes",
      	"viewOn" : "lightningStrikes",
      	"pipeline" : [
      		{
      			"$match" : {
      				"datetime" : {
      					"$gte" : new Date(new Date() - 1000*60*20)
      				}
      			}
      		}
      	]
      }
      

            Assignee:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Reporter:
            michaelfdias Michael Felix Dias
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: