mongoose-ops
v0.1.3
Published
Straightforward MongoDB CRUD operations over Mongoose
Downloads
7
Readme
Description
A thin layer on top of Mongoose that facilitates MongoDB CRUD operations using a straightforward API.
Disclaimer: this package is experimental — use at your own peril.
Usage
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
Creative Commons Zero v1.0 Universal