Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1696

browser-repl does not handle literal objects that translate to EJSON well

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Browser Module
    • None
    • 2
    • Developer Tools

      db.test.insertOne({a: new Date()});
      db.test.insertOne({a: {"$date": {"$numberLong": "1706205816000"}}});
      db.test.find();
      {
        _id: ObjectId('65b2a243061433116eb4f3c2'),
        a: 2024-01-25T18:02:43.966Z
      }
      {
        _id: ObjectId('65b2a27d061433116eb4f3c3'),
        a: 2024-01-25T18:03:36.000Z // Both inserted objects rendered as dates.
      }
      db.test.aggregate({$project: {d: {$subtract: ["$a", "$a"]}}}) - fails with
      MongoServerError: PlanExecutor error during aggregation :: caused by :: Only numbers and dates are allowed in an $subtract expression
      
      db.test.deleteOne({_id: ObjectId('65b2a27d061433116eb4f3c3')}); // one with {$date: {$numberLong: ..}}
      db.test.aggregate({$project: {d: {$subtract: ["$a", "$a"]}}}) - works
      {
        _id: ObjectId('65b2a243061433116eb4f3c2'),
        d: 0
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            anna.henningsen@mongodb.com Anna Henningsen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: