Skip to content

directAccess + query.aggregate + dates no longer work #7748

Closed
@jonas-db

Description

@jonas-db

New Issue Checklist

Issue Description

When you start the server with the option directAccess, the execution of a pipeline does not return results when you pass a Date instance to match.

Steps to reproduce

  1. The following test fails when directAccess is set to true and 'date': date
  2. The following test passes when directAccess is set to false and 'date': date
  3. The following test passes when directAccess is set to true or false and date : date.toISOString().

It remains unclear whether this behaviour was intended in previous versions (<5)

    it('fails', async () => {
        const registration = await Parse.User.signUp("jonas", "test", {});
        expect(registration.id).to.be.exist

        const user = await Parse.User.logIn("jonas", "test");
        expect(user.get('sessionToken')).to.be.exist
        expect(user.id).to.be.exist

        const TestObject = Parse.Object.extend('TestObject');

        const date = new Date()
        const testObject = await new TestObject({
            date: date,
        }).save({}, { useMasterKey : true });

        const match = {
            'date': { "$gte": date, "$lte": date } // Does not work when directAccess is true
            //'date': { "$gte": date.toISOString(), "$lte": date.toISOString()} // Works for both
        }
        
        console.log(match)

        const pipeline = [
            {
                "$match" : match
            }
        ]
        const query = new Parse.Query(TestObject);
        const result = await query.aggregate(pipeline).catch(e => e);
        console.log("results=",util.inspect(result, { showHidden: false, depth: null }))

        const query2 = new Parse.Query(TestObject);
        const result2 = await query2.equalTo('date', date).find().catch(e => e);
        console.log("results2=",util.inspect(result2, { showHidden: false, depth: null }))

        expect(result).to.be.lengthOf(1)
        expect(result2).to.be.lengthOf(1)
        expect(result[0].objectId).to.be.equal(result2[0].id)
    });

Actual Outcome

When (1)

results= []
results2= [
  ParseObjectSubclass {
    className: 'TestObject',
    _objCount: 9,
    id: 'jXEY7xFC3a'
  }
]

Expected Outcome

When (2) or (3)

results= [
  {
    date: { __type: 'Date', iso: '2021-12-28T13:51:11.961Z' },
    createdAt: '2021-12-28T13:51:11.962Z',
    updatedAt: '2021-12-28T13:51:11.962Z',
    objectId: 'xNLwllPXlu'
  }
]
results2= [
  ParseObjectSubclass {
    className: 'TestObject',
    _objCount: 9,
    id: 'xNLwllPXlu'
  }
]

Environment

Server

  • Parse Server version: ^5.0.0-beta.4
  • Operating system: macos
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): mongodb
  • Database version: 5.0.3
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): na
  • SDK version: na

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions