https://github.com/itsabdelrahman/mongoose-ops
🦡 Straightforward MongoDB CRUD operations over Mongoose
https://github.com/itsabdelrahman/mongoose-ops
Last synced: 22 days ago
JSON representation
🦡 Straightforward MongoDB CRUD operations over Mongoose
- Host: GitHub
- URL: https://github.com/itsabdelrahman/mongoose-ops
- Owner: itsabdelrahman
- License: cc0-1.0
- Created: 2020-05-22T00:41:11.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-11T17:21:36.000Z (almost 4 years ago)
- Last Synced: 2025-04-12T06:54:29.621Z (22 days ago)
- Language: TypeScript
- Homepage:
- Size: 900 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Description
A thin layer on top of [Mongoose](https://mongoosejs.com/) that facilitates [MongoDB](https://www.mongodb.com/) CRUD operations using a straightforward API.
_Disclaimer: this package is experimental — use at your own peril._
## Installation
```bash
❯ npm install --save mongoose-ops
```## Usage
```js
import {
count,
getOne,
getMany,
createOne,
createMany,
updateOne,
deleteOne,
deleteMany,
} from 'mongoose-ops';/* Count documents */
const usersCount = await count(userModel)();/* Get document */
const existingUser = await getOne(userModel)({
query: {
_id: '507f1f77bcf86cd799439011',
},
});/* Get multiple documents */
const existingUsers = await getMany(userModel)({
query: {
name: new RegExp('^B[a-z]+'),
},
sorting: {
createdAt: 'DESCENDING',
},
pagination: {
skip: 0,
limit: 10,
},
});/* Create document */
const createdUser = await createOne(userModel)({
document: {
name: 'John',
},
});/* Create multiple documents */
const createdUsers = await createMany(userModel)({
documents: [
{
name: 'John',
},
{
name: 'Jane',
},
],
});/* Update document */
const updatedUser = await updateOne(userModel)({
query: {
_id: '507f1f77bcf86cd799439011',
},
document: {
name: 'Elizabeth',
},
});/* Delete document */
const deletedUser = await deleteOne(userModel)({
query: {
_id: '507f1f77bcf86cd799439011',
},
});/* Delete multiple documents */
const deletedUsers = await deleteMany(userModel)({
query: {
name: new RegExp('^B[a-z]+'),
},
});
```## License
[CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/)