Open lcavero opened 6 years ago
@lcavero Thanks for posting, we'll take a look as soon as possible.
For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.
Hi @lcavero, thanks for providing info about this duplicate phenomenon when the model config parameter "schema" is set to true.
@lcavero Feel free to submit a PR for sails-mongo to patch this and we'll take a look.
Hi, has there been any patch for this error yet? I am trying to use Waterline with Mongo DB but this issue still pops up when trying to archive.
Just to make a note on my work around for anyone running into this error. I created a helper function that calls archive/archiveOne and catches the error where it checks if it was added to archive and if so call the destroy method.
@simplewilliam - Thanks for taking the time to provide a workaround - any example code or repo is further welcome. Currently, we have several plans in store for sails-mongo, I'll bring this one up with the team.
@johnabrams7 - Thanks for looking into it, the following code can be placed within a helper function to act as an alternative for the archive function when trying to archive by id
fn: async function(inputs, exits) {
const { model, id } = inputs;
let archivedDocument;
try {
archivedDocument = await model.archiveOne({ id });
} catch (err) {
var archived = await Archive.find({
originalRecordId: id,});
if (archived) {
archivedDocument = await model.destroyOne({ id });
}
}
return exits.success(archivedDocument);
}
Same here, can not do:
Model.archiveOne({id: id})
Got the following error:
Could not use the provided
whereclause. Could not filter by
_id:
_idis not a recognized attribute for this model
@solovieff We tested with the latest version of the adapter and it worked for us. Could you create a repo reproducing the error?
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.
With either of the two cases (id or _id) the following error occurs
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!