6.0.2 • Published 6 years ago
mongooster v6.0.2
MONGOOSTER
This is a small helper library to make interfacing with mongoose a little bit easier.
Schemas
import { Collection, Default, Document, Optional, Required } from "mongooster";
import ulid from "ulid";
export interface IUser extends Document {
_id: string;
name: string;
age?: number;
}
export const UserSchema = new Schema({
_id: Default(String, ulid),
name: Required(String),
age: Optional(Number),
});
export const Users = new Collection<IUser>("users", UserSchema);
Middleware
import { Collection, Default, Document, Optional, Required, UpdateOp } from "mongooster";
import ulid from "ulid";
export interface IUser extends Document {
_id: string;
name: string;
age?: number;
}
export const UserSchema = new Schema({
_id: Default(String, ulid),
name: Required(String),
age: Optional(Number),
});
export const middleware = new Middleware<IUser>({
fetchDoc: true,
postUpdate: (op: UpdateOp, doc?: IUser): Promise<any> => {
console.log("Updated user!");
console.log("if fetchDoc: false, doc will be undefined!");
console.log("setting it to true is handy, but comes with the performance penalty of an additional database read.");
return Promise.resolve();
},
})
export const Users = new Collection<IUser>("users", UserSchema, middleware);
6.0.2
6 years ago
6.0.0
6 years ago
5.1.2
6 years ago
5.1.0
6 years ago
5.0.0
6 years ago
4.0.0
6 years ago
3.5.2
7 years ago
3.5.0
7 years ago
3.4.2
7 years ago
3.4.1
7 years ago
3.4.0
7 years ago
3.3.0
7 years ago
3.2.0
7 years ago
3.1.0
7 years ago
3.0.0
7 years ago
2.0.1
7 years ago
2.0.0
7 years ago
1.5.2
7 years ago
1.5.1
7 years ago
1.5.0
7 years ago
1.4.0
7 years ago
1.3.0
7 years ago
1.2.1
7 years ago
1.2.0
7 years ago
1.1.0
7 years ago
1.0.0
7 years ago