A concrete implementation of js-entity-repos for mongo.
- Install it with
npm i @js-entity-repos/mongo
. - For each entity you will need to do the following.
export interface TodoId {
readonly id: string;
}
export interface TodoEntity extends TodoId {
readonly description: string;
readonly completed: boolean;
}
import facade from '@js-entity-repos/mongo/dist/utils/connectToCollection';
const todoFacadeConfig = {
collection: connectToCollection({
collectionName: 'todos',
dbName: 'todoapp',
url: 'mongodb://localhost:27017',
}),
entityName: 'todo',
};
import facade from '@js-entity-repos/mongo/dist/facade';
const todosFacade = facade<TodoId, TodoEntity>(todoFacadeConfig);