parse-server
parse-server copied to clipboard
Option `select()` is ignored when using `find()`
New Issue Checklist
- [x] I am not disclosing a vulnerability.
- [x] I am not just asking a question.
- [x] I have searched through existing issues.
- [x] I can reproduce the issue with the latest version of Parse Server.
Issue Description
I want to get only some fields using select() when querying multiple User,
It worked if I query just one User (with first), but not with find().
Instead it returned all fields.
Steps to reproduce
const users = await new Parse.Query(Parse.User)
.select('firstName')
.find();
const usersJSON = users.map(user => user.toJSON());
console.log(usersJSON );
Actual Outcome
[
{
"username": "[email protected]",
"email": "[email protected]",
"lastName": "ULast",
"firstName": "User3",
"seen": false,
"createdAt": "2022-08-09T06:52:01.791Z",
"updatedAt": "2022-08-10T06:34:18.644Z",
"isOnline": true,
"ACL": {
"*": {
"read": true
},
"6CNboVpyma": {
"read": true,
"write": true
}
},
"sessionToken": "r:1b9aaeaac68c7cb03cc660a606eeaefe",
"objectId": "6CNboVpyma"
},
{
"firstName": "User1",
"createdAt": "2022-08-10T06:32:40.022Z",
"updatedAt": "2022-08-10T06:32:40.022Z",
"ACL": {
"*": {
"read": true
},
"W3LGz80lMv": {
"read": true,
"write": true
}
},
"objectId": "W3LGz80lMv"
}
]
Expected Outcome
[
{
"firstName": "User3",
"createdAt": "2022-08-09T06:52:01.791Z",
"updatedAt": "2022-08-10T06:34:18.644Z",
"objectId": "6CNboVpyma"
},
{
"firstName": "User1",
"createdAt": "2022-08-10T06:32:40.022Z",
"updatedAt": "2022-08-10T06:32:40.022Z"
"objectId": "W3LGz80lMv"
}
]
Environment
Server
- Parse Server version:
5.2.4 - Operating system:
Microsoft Windows 10 - Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
Local
Database
- System (MongoDB or Postgres):
MongoDB - Database version:
5 - Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
MongoDB Atlas
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc):
JavaScript - SDK version:
3.4.3
Logs
Thanks for opening this issue!
- 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
A PR with a failing test is needed here. Similar tests already exists:
https://github.com/parse-community/parse-server/blob/4c29d4d23b67e4abaf25803fe71cae47ce1b5957/spec/ParseObject.spec.js#L1945-L1978
The basic test indeed only uses first(), so maybe you could add a simple test for find():
https://github.com/parse-community/parse-server/blob/e9d23830a3a34d7d0762f835bd918f5978ab0338/spec/ParseQuery.spec.js#L3184
@tiavina-mika Do you have any update on this? Can we close this?
If we cannot reproduce this, maybe we should at least improve testing and add a test for find(), as I commented above.
I think this is as expected. createdAt, ACL, updatedAt, objectId are always returned regardless of .select.
However, I wasn't able to replicate the issue of other keys coming through too. Here's my passing test:
it('can select on user class', async () => {
const [bob] = await Promise.all([
Parse.User.signUp('bob', 'password', { firstName: 'bob' , lastName: 'bill' }),
Parse.User.signUp('bob2', 'password', { firstName: 'bob2', lastName: 'bill2' }),
]);
const users = await new Parse.Query(Parse.User)
.select('firstName')
.find({ sessionToken: bob.get('sessionToken') });
const allKeys = [
...new Set(
users
.map(user => Object.keys(user.toJSON()))
.flat()
.sort()
),
];
expect(allKeys).toEqual(['ACL', 'createdAt', 'firstName', 'objectId', 'updatedAt']);
});
This test creates two users with firstName and lastName, and then attempts to run a query with select. After that, it creates a unique array (allKeys) with all the returned keys from both find objects.
In your case it could be that [email protected] is the currentUser, and the additional keys are showing up as it's reference internally/in memory is the same.
To be closed if no further answer from @tiavina-mika due to unable to replicate.
Closing due to not reproducible.