question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$select doesn't work in find?

See original GitHub issue

$select doesn’t work in find operation. I found that the source code for $select is not the same as that in other packages like feathers-mongodb or feathers-nedb. Normally the code would be like this:

    // $select uses a specific find syntax, so it has to come first.
    if (filters.$select) {
      query = this.Model.find(params.query, getSelect(filters.$select));
    }

but in feathers-mongoose (via github) it is like:

    // $select uses a specific find syntax, so it has to come first.
    if (filters.$select && filters.$select.length) {
      let fields = {};

      for (let key of filters.$select) {
        fields[key] = 1;
      }

      query.select(fields);
    }

and furthermore, in the actually feathers-mongoose npm package (v3.3.6) the source code is:

      // $select uses a specific find syntax, so it has to come first.
      if (filters.$select && filters.$select.length) {
        var fields = {};

        var _iteratorNormalCompletion = true;
        var _didIteratorError = false;
        var _iteratorError = undefined;

        try {
          for (var _iterator = filters.$select[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
            var key = _step.value;

            fields[key] = 1;
          }
        } catch (err) {
          _didIteratorError = true;
          _iteratorError = err;
        } finally {
          try {
            if (!_iteratorNormalCompletion && _iterator.return) {
              _iterator.return();
            }
          } finally {
            if (_didIteratorError) {
              throw _iteratorError;
            }
          }
        }

        query.select(fields);
      }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
beeplincommented, Mar 22, 2016

I just cloned feathers-chat project, changed it’s service from nedb to mongoose, and modify /public/react-chat/app.jsx L128 to:

    // Find the last 10 messages
    messageService.find({
      query: {
        $select: {
          _id: 0,
          'text': 0
        },
        $sort: { createdAt: -1 },
        $limit: this.props.limit || 10
      }
    }).then(page => this.setState({ messages: page.data.reverse() }));

other stuffs work perfectly including $sort, &skit and #limit, but $select seems to be ignored.

0reactions
beeplincommented, Mar 23, 2016

got it. Thanks~

来自 魅族 MX5

-------- 原始邮件 -------- 发件人:Marshall Thompson notifications@github.com 时间:周三 3月23日 16:10 收件人:feathersjs/feathers-mongoose feathers-mongoose@noreply.github.com 抄送:Beep LIN beeplin@gmail.com 主题:Re: [feathers-mongoose] $select doesn’t work in find? (#71)

@beeplin This is part of our shared tests for all adapters: https://github.com/feathersjs/feathers-service-tests/blob/master/src/common-tests.js#L166 So all of them should support it. —You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery find not working for select="selected" - Stack Overflow
I tried $('#mySelector').find(":selected") . It returns [] . But if my options have only selected property instead of selected ...
Read more >
"Find" is not working in excel - Microsoft Community
For the find functionality, select the Home ribbon and then the Find & Select (far right of the Home ribbon) and then select...
Read more >
How to Fix When Excel Find Is Not Working
To fix this mistake, first click the Find All (or Find Next) button, and then press the Replace All (or Replace). excel find...
Read more >
"Select All Occurrences of Find Match" doesn't work if ... - GitHub
It's a bug because "Select All Occurrences of Find Match" should have consistent behaviour; it shouldn't matter if you have the find panel...
Read more >
Repair a storage device in Disk Utility on Mac - Apple Support
In the Disk Utility app on your Mac, choose View > Show All Devices. If Disk Utility isn't open, click the Launchpad icon...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found