1.76.3 • Published 11 months ago
@biorate/mongodb v1.76.3
Mongodb
Mongodb ORM connector based on mongoose and typegoose
Examples:
import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import {
Severity,
modelOptions,
Prop,
MongoDBConnector,
IMongoDBConnector,
model,
ReturnModelType,
} from '@biorate/mongodb';
// Define models
@modelOptions({
options: {
allowMixed: Severity.ALLOW,
},
schemaOptions: { collection: 'test', versionKey: false },
})
export class TestModel {
@Prop()
firstName: string;
@Prop()
lastName: string;
@Prop()
age: number;
}
// Define root
export class Root extends Core() {
@inject(MongoDBConnector) public connector: IMongoDBConnector;
@model(TestModel) public test: ReturnModelType<typeof TestModel>;
}
// Bind dependencies
container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<IMongoDBConnector>(MongoDBConnector).toSelf().inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();
// Configure
container.get<IConfig>(Types.Config).merge({
MongoDB: [
{
name: 'connection',
host: 'mongodb://localhost:27017/',
options: {
useNewUrlParser: true,
useUnifiedTopology: true,
dbName: 'test',
},
},
],
});
(async () => {
const root = container.get<Root>(Root);
await root.$run();
await root.connector.connection().dropDatabase();
const connection = root.connector.connection('connection'); // Get connection instance
console.log(connection);
await new root.test({
firstName: 'Vasya',
lastName: 'Pupkin',
age: 36,
}).save(); // insert data into test collection
// Get data from database
const data = await root.test.find({ firstName: 'Vasya' }, { _id: 0 });
console.log(data); // {
// firstName: 'Vasya',
// lastName: 'Pupkin',
// age: 36,
// }
})();
Learn
- Documentation can be found here - docs.
Release History
See the CHANGELOG
License
Copyright (c) 2021-present Leonid Levkin (llevkin)
1.76.3
11 months ago
1.65.4
1 year ago
1.58.1
1 year ago
1.54.0
1 year ago
1.38.2
2 years ago
1.38.3
2 years ago
1.38.1
2 years ago
1.38.4
2 years ago
1.42.2
2 years ago
1.42.1
2 years ago
1.30.12
2 years ago
1.29.0
2 years ago
1.28.1
2 years ago
1.28.0
2 years ago
1.26.0
2 years ago
1.27.2
2 years ago
1.27.0
2 years ago
1.27.1
2 years ago
1.25.2
2 years ago
1.24.0
2 years ago
1.20.1
3 years ago
1.11.2
3 years ago
1.7.1
3 years ago
1.7.0
3 years ago
1.6.0
3 years ago
1.0.0
3 years ago
0.30.11
3 years ago
0.30.12
3 years ago
0.30.2
3 years ago
0.30.17
3 years ago
0.30.18
3 years ago
0.30.0
3 years ago
0.30.19
3 years ago
1.4.0
3 years ago
1.2.2
3 years ago
0.30.9
3 years ago
0.30.7
3 years ago
0.30.6
3 years ago
0.30.5
3 years ago
0.29.1
3 years ago
0.28.3
3 years ago
0.28.0
3 years ago
0.27.3
3 years ago
0.27.0
3 years ago
0.26.0
3 years ago