Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find() fields straight up don't work #302

Closed
eddie-englund opened this issue May 28, 2021 · 2 comments
Closed

find() fields straight up don't work #302

eddie-englund opened this issue May 28, 2021 · 2 comments

Comments

@eddie-englund
Copy link

eddie-englund commented May 28, 2021

I've been trying to use the "fields" flag that's on the find() method, but it appears to return ALL indexes no matter what in the collection.

const tickets: IPaginateResult<ITicket> = await find(getDB().tickets, {
    limit: 50,
    fields: { _id: 1, assignee: 'github|16852656', status: TicketStatus.open },
    next: req.query.hasNext == 'true' ? true : false,
  });

This in turn returns this data:

mingo-chan_1                       | {
mingo-chan_1                       |   results: [
mingo-chan_1                       |     {
mingo-chan_1                       |       authorId: 'github|16852656',
mingo-chan_1                       |       author: 'Eddie Englund',
mingo-chan_1                       |       assignee: 'github|16852656',
mingo-chan_1                       |       status: 1,
mingo-chan_1                       |       createdAt: 2021-05-28T17:04:56.093Z,
mingo-chan_1                       |       isStarred: false,
mingo-chan_1                       |       tags: [],
mingo-chan_1                       |       labels: [],
mingo-chan_1                       |       isUpdated: true,
mingo-chan_1                       |       messages: [Array],
mingo-chan_1                       |       notes: [],
mingo-chan_1                       |       personnelView: [Array]
mingo-chan_1                       |     },
mingo-chan_1                       |     {
mingo-chan_1                       |       authorId: 'github|16852656',
mingo-chan_1                       |       author: 'Eddie Englund',
mingo-chan_1                       |       status: 1,
mingo-chan_1                       |       createdAt: 2021-05-28T17:04:54.317Z,
mingo-chan_1                       |       isStarred: false,
mingo-chan_1                       |       tags: [],
mingo-chan_1                       |       labels: [],
mingo-chan_1                       |       isUpdated: true,
mingo-chan_1                       |       messages: [Array],
mingo-chan_1                       |       notes: [],
mingo-chan_1                       |       personnelView: [Array]
mingo-chan_1                       |     }
mingo-chan_1                       |   ],
mingo-chan_1                       |   previous: 'eyIkb2lkIjoiNjBiMTIyYjgyYTAyNDMwMDFkZmE4NzI0In0',
mingo-chan_1                       |   hasPrevious: false,
mingo-chan_1                       |   next: 'eyIkb2lkIjoiNjBiMTIyYjYyYTAyNDMwMDFkZmE4NzIzIn0',
mingo-chan_1                       |   hasNext: false
mingo-chan_1                       | }

But clearly the above shouldn't be passed as A the assignee is null on the second user but also neither of them actually have _id of 1.

Note that I am using the native driver here.

@eddie-englund
Copy link
Author

Nvm I'm retarded.

@eddie-englund
Copy link
Author

What I did is that you need to put it in the query object and not the fields object 🤦

Example:

const tickets: IPaginateResult<ITicket> = await find(getDB().tickets, {
		limit: 50,
		query: { status: TicketStatus.open, $or: [{ assignee: { $type: 'null' } }, { assignee: { $exists: false } }] },
		next: req.query.hasNext == 'true' ? true : false,
	});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant