@s4p/smdb
v0.2.0
Published
Subset of MongoDB's API (the most used operations)
Downloads
84
Readme
SMDB
A subset of MongoDB's API (the most used operations) simple database, support mongo / memory / file driver
How to use
connet to db
import { SubsetMongo } from '@s4p/smdb'; import { MongoClient } from 'mongodb'; import DataStore from '@s4p/nedb'; // mongodb const smdb = new SubsetMongo(MongoClient); smdb.connect('mongodb://localhost:27017/test', { timestamp: true }); // memory const smdb = new SubsetMongo(DataStore, 'memory', { timestamp: true }); // dir (file storage) const smdb = new SubsetMongo(DataStore); smdb.connect('dir:///some/absolute/dir', { timestamp: true }); // disconnect await smdb.disconnect();
create / get collection
const personCollection = smdb.collection('person');
collection CRUD
insertOne(doc: OptionalUnlessRequiredId<T>): Promise<InsertOneResult>; insertMany(docs: OptionalUnlessRequiredId<T>[]): Promise<InsertManyResult>; deleteOne(filter: Filter<T>): Promise<DeleteResult>; deleteMany(filter: Filter<T>): Promise<DeleteResult>; updateOne( filter: Filter<T>, document: UpdateFilter<T>, options?: UpdateOptions, ): Promise<UpdateResult<T>>; updateMany( filter: Filter<T>, document: UpdateFilter<T>, options?: UpdateOptions, ): Promise<UpdateResult<T>>; findOne(query: Filter<T>, options?: FindOptions): Promise<(T & { _id?: any }) | null>; find(query: Filter<T>, options?: FindOptions): Promise<WithId<T>[]>; countDocuments(query?: Filter<T>): Promise<number>; createIndex( fieldOrSpec: IndexSpecification, options?: CreateIndexesOptions, ): Promise<string>; dropIndex(indexName: string): Promise<void>; listIndexes(): Promise<ListIndexesResult[]>; drop(): Promise<boolean>;
Thanks
Dev
how to generate MongoDB types
pnpm exec dts-bundle-generator -o my.d.ts ./index.ts --external-inlines mongodb --external-inlines bson
License
MIT