balderdashy / balderdashy/sails

Archive by id or _id fails in MongoDb

Open
#4,436 9 comments 0 reactions 0 assignees View on GitHub
bug mongo orm repro please
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Sails version**: 1.0.2
**Node version**: v8.10.0
**NPM version**: 3.5.2
**DB adapter name**: sails-mongo
**DB adapter version**: 1.0.1
**Operating system**: "Ubuntu 18.04"



Hello, I have detected that the "archive" method fails in MongoDb when you set the config property "schema" to true and try to do a "soft delete" for id or _id.

```
fn: async function (inputs, exits) {
// That line fails
await SharedDocument.archive({id: "5b0fae71d8785b29956bf65f"})

// That line fails too
await SharedDocument.archive({_id: "5b0fae71d8785b29956bf65f"})

return exits.success({ status: "Ok" });
}
```

With either of the two cases (id or _id) the following error occurs
```
Could not use the provided `where` clause. Could not filter by `_id`: `_id` is not a recognized attribute for this model (`shareddocument`). And since the model declares `schema: true`, this is not allowed.
```
Then, if you show the database, there are two copies of the record, one in SharedDocument, and other in archive, so I guess sails is failing to delete the original.
**This only happens if the model config parameter "schema" is set to true**

Thank you guys!

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with SharedDocument.archive({id: ...}) and SharedDocument.archive({_id: ...}) while the model has schema: true, using the versions and Ubuntu environment listed in the issue. Inspect the archive path and MongoDB adapter behavior around the reported `_id` filtering error; done means both forms archive the record without leaving the original copy.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.