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

"Error: Object is not a document stored in the collection" in "FIND and REMOVE" #6

Open
atellezr opened this issue Dec 10, 2017 · 1 comment

Comments

@atellezr
Copy link
Contributor

Hi,

when I try to use the FIND and REMOVE method using as input an existing criteria I get this error:

Error: Object is not a document stored in the collection

Searching in internet (techfort/LokiJS#544 and techfort/LokiJS#532) I've found that I don't have the attribute $loki in the input of the remove function, in the findandremove section:

As result of the sentence message.payload = coll.find(input); I have this: [{"dato1":7}]
and the following sentence coll.chain().find(input).remove(); fails with the mentioned error

In the database what I have is this:

"data":[{"dato1":7}]

@atellezr
Copy link
Contributor Author

After checking a while the code I've found out the problem:

the insert method is implemented as:

        } else if (nd.method === 'insert') {
          if (nd.input === 'true') {
            message = Object.assign({}, coll.insert(input));
          } else {
            message.payload = coll.insert(input);
          }

In the part when the nd.input is not true, the message.payload is assigned directly to the result object from the insert
Later, there are these 2 deletes:

        delete message.payload.meta;
        delete message.payload.$loki;

This has sense in order to avoid showing the meta and $loki attributes outside, but since the operation is not over a copy of the insert result, the delete is done in the ouutput object and also over the the result of the insert, so in the database are lost both attributes

I'm going to prepare a pull request with my proposal for fixing this

Thanks!
Regards

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