riyadhalnur / mongoose-softdelete Goto Github PK
View Code? Open in Web Editor NEWSoft delete MongoDB documents
Home Page: http://riyadhalnur.github.io/mongoose-softdelete
License: MIT License
Soft delete MongoDB documents
Home Page: http://riyadhalnur.github.io/mongoose-softdelete
License: MIT License
Looking through the docs, It doesnt look like it, but I thought id make sure. Usually the soft deletes or 'paranoid' setting will exclude the soft deleted documents from future queries, until they are restored. Is that possible with this plugin?
node_modules/mongoose-softdelete/index.d.ts:1:42 - error TS2305: Module '"mongoose"' has no exported member 'DocumentQuery'.
1 import { Document, Model, Query, Schema, DocumentQuery } from "mongoose";
~~~~~~~~~~~~~
node_modules/mongoose-softdelete/index.d.ts:15:38 - error TS2314: Generic type 'Query<ResultType, DocType>' requires 2 type argument(s).
15 isDeleted: (condition: Boolean) => Query<ISoftDeletedDocument>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/mongoose-softdelete/index.d.ts:18:33 - error TS2314: Generic type 'Query<ResultType, DocType>' requires 2 type argument(s).
18 export type ISoftDeletedQuery = Query<ISoftDeletedDocument> & IQueryMethods;
~~~~~~~~~~~~~~~~~~~~~~~~~~~
[3:54:37 PM] Found 3 errors. Watching for file changes.
I think your softdelete system is based on deleted field, but when i softdeleting, mongoose validating, and document not soft deleted. Can you help me? any config that i miss or this is a bug. Thank you before.
that will augment the query with {deleted: false} before calling the DB
Hi im trying to use soft delete with typescript
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/globant/Documents/repos/spybee/node_modules/mongoose-softdelete/src/mongoose-softdelete.js
require() of ES modules is not supported.
require() of /home/globant/Documents/repos/spybee/node_modules/mongoose-softdelete/src/mongoose-softdelete.js from /home/globant/Documents/repos/spybee/src/models/user.ts is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename mongoose-softdelete.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/globant/Documents/repos/spybee/node_modules/mongoose-softdelete/package.json.
Package.json
{
"name": "spybee",
"version": "1.0.0",
"description": "Spybee backend",
"main": "app.js",
"scripts": {
"clean": "rm -r -f ./build",
"tsc": "tsc",
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "nodemon",
"start:local": "ts-node ./src/server.ts",
"build": "tsc -p tsconfig.json",
"add-develop": "git remote add develop https://git.heroku.com/spybee-api.git",
"push-develop": "git push develop develop:master",
"start": "node ./build/src/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@sendgrid/mail": "^7.4.2",
"@types/bcrypt": "^3.0.0",
"@types/cors": "^2.8.9",
"@types/express": "^4.17.11",
"@types/mongoose": "^5.10.3",
"bcrypt": "^5.0.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"eslint": "^5.15.3",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-jest": "^22.3.0",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-simple-import-sort": "^4.0.0",
"express": "^4.17.1",
"joi": "^17.3.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.11.12",
"mongoose-softdelete": "^1.2.0",
"nodemon": "^2.0.7",
"ts-node": "^8.0.3",
"typescript": "^4.1.3"
},
"devDependencies": {
"@types/jsonwebtoken": "^8.5.0",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.4.2"
}
}
Hi, everything is in the question:
Are there any plans on doing a TypeScript definition? Would be amazing to have the autocompletion features and validation.
Thanks for any information :)
Tom
I have imported the package as instructed as follows:
const softDelete = require('mongoose-softdelete');
But whenever I'm running the project, I'm facing an error like below:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/subhasis/Work/mpac-dispenser/node_modules/mongoose-softdelete/src/mongoose-softdelete.js require() of ES modules is not supported. require() of /home/subhasis/Work/mpac-dispenser/node_modules/mongoose-softdelete/src/mongoose-softdelete.js from /home/subhasis/Work/mpac-dispenser/models/medicine.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename mongoose-softdelete.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/subhasis/Work/mpac-dispenser/node_modules/mongoose-softdelete/package.json.
Kindly fix this issue otherwise give a solution to overcome this. If I comment out the require line then it runs fine.
I've tried out this plugin and noticed when I perform a soft delete I can no longer find it in the database.
Is this expected behaviour?
How do you restore an object if you are unable to find it again.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.