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

How to use $set in patch or update? #323

Closed
patrickpereira opened this issue May 4, 2016 · 5 comments
Closed

How to use $set in patch or update? #323

patrickpereira opened this issue May 4, 2016 · 5 comments

Comments

@patrickpereira
Copy link

Hi Feathers team,

I've been trying to use $set in a update or a patch, but I can't seem to figure out how to use it. I'm using feathers with Mongoose.

Any help would be highly appreciated.

Best regards
Patrick

@marshallswain
Copy link
Member

marshallswain commented May 4, 2016

@patrickpereira, feathers-mongoose uses $set internally in PATCH, already: https://github.com/feathersjs/feathers-mongoose/blob/master/src/service.js#L183

@daffl
Copy link
Member

daffl commented May 5, 2016

Yes, patch uses $set. You should also be able to use $set in update. app.service('messages').update(id, { $set: mydata }) didn't work?

@patrickpereira
Copy link
Author

patrickpereira commented May 5, 2016

Thanks for the swift replies, I forgot to mention that I dont have the id, so I was putting in null instead in the update service. Furthermore it's a subdocument that I'm trying to find and update with $set.

So far I had to manually require the mongoose model and I solved it like this:

text_messages.findOneAndUpdate({
            'result.customid': params.query.customid,
            'result.id': params.query.id
        }, {
            $set: {
                "result.$.status": params.query.status,
                "result.$.date": new Date(parseInt(params.query.date)*1000),
                "result.$.statusText": statusCodes[parseInt(params.query.status)]
            }
        }, {
            new: true
        },
        (err, res) => {
            console.log(err,res);
            this.emit('status', res);
        })

Is there a better way to do this using the builtin services in feathers?

@ekryski
Copy link
Contributor

ekryski commented May 21, 2016

I think this issue is somewhat related. Basically you want to be able to supply additional query options similar to how we handle it with sequelize. We have an open issue for that.

In the mean time @patrickpereira your solution is totally fine. I'm going to close this as we can track progress against the open mongoose issue.

@lock
Copy link

lock bot commented Feb 7, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants