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 can I pass additional query parameters in a REST put operation? #162

Closed
CosmoMyzrailGorynych opened this issue Feb 10, 2017 · 3 comments

Comments

@CosmoMyzrailGorynych
Copy link

I would like to update an item inside a document's array via positional operator $ of Mongoose/MongoDB query, and thus need to not only pass ID of an updated document but also an additional query for array objects. Despite all attempts Mongoose says that "The positional operator did not find the match needed from the query. Unexpanded update: faculcies.$.name".

I call 'PUT' on URL like /univercities/{docID}?faculcies._id={faculcyID} via fetch:

fetch(`/univercities/${this.parent.univercity._id}?faculcies._id=${this.faculcy._id}`, {
    method: 'put',
    body:  JSON.stringify({
        '$set': {
            'faculcies.$.name': this.faculcy.name
        }
    }),
    headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        Authorization: sessionStorage.accessToken
    }
})
.then( … )

The hook.params.query becomes { 'faculcies._id': '589d3fc48fe3632ed854beee' }, but this additional query seems to be ignored. All IDs are valid and there are no spelling mistakes.
It is also impossible to 'PUT' something on /univercities?_id={univercityID}&faculcies._id={faculcyID}.

Am I missing something? Or is it something just not implemented?

@marshallswain
Copy link
Member

@CosmoMyzrailGorynych I haven't tried that, yet. Can you set a breakpoint in feathers-mongoose and verify that the data is getting passed in properly?

@daffl
Copy link
Member

daffl commented Feb 10, 2017

From what I understand, faculcies is an array but faculcies._id will try to query for { faculcies: { _id } }. You will have to use the $elemMatch selector to find items in an array.

@daffl daffl closed this as completed Feb 15, 2017
@DominikTrenz
Copy link

I can't get it working neither. I tried this:
userService.update({ "_id":"mainDocumentID", "subdocs": {$elemMatch: {_id: "someId"}} }, { $set:{ "subdocs.$.last_name":"New Lastname" } })
and that:
userService.update({ "_id":"mainDocumentID", "subdocs._id":"someId" }, { $set:{ "subdocs.$.last_name":"New Lastname" } })
as supposed in this threads:
https://stackoverflow.com/questions/20262405/update-array-element-by-id-with-mongo-query
https://stackoverflow.com/questions/37612448/mongodb-positional-operator-error

What am i missing?

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

4 participants