mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
Merge pull request #23577 from ddwwcruz/mongodb-enhanced-typings
Mongodb enhanced typings
This commit is contained in:
Vendored
+71
-32
@@ -482,13 +482,13 @@ export interface Collection<TSchema = Default> {
|
||||
createIndexes(indexSpecs: Object[], options?: {session?: ClientSession}): Promise<any>;
|
||||
createIndexes(indexSpecs: Object[], options: {session?: ClientSession}, callback: MongoCallback<any>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#deleteMany */
|
||||
deleteMany(filter: Object, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
||||
deleteMany(filter: Object, options?: CommonOptions): Promise<DeleteWriteOpResultObject>;
|
||||
deleteMany(filter: Object, options: CommonOptions, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
||||
deleteMany(filter: FilterQuery<TSchema>, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
||||
deleteMany(filter: FilterQuery<TSchema>, options?: CommonOptions): Promise<DeleteWriteOpResultObject>;
|
||||
deleteMany(filter: FilterQuery<TSchema>, options: CommonOptions, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#deleteOne */
|
||||
deleteOne(filter: Object, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
||||
deleteOne(filter: Object, options?: CommonOptions & { bypassDocumentValidation?: boolean }): Promise<DeleteWriteOpResultObject>;
|
||||
deleteOne(filter: Object, options: CommonOptions & { bypassDocumentValidation?: boolean }, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
||||
deleteOne(filter: FilterQuery<TSchema>, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
||||
deleteOne(filter: FilterQuery<TSchema>, options?: CommonOptions & { bypassDocumentValidation?: boolean }): Promise<DeleteWriteOpResultObject>;
|
||||
deleteOne(filter: FilterQuery<TSchema>, options: CommonOptions & { bypassDocumentValidation?: boolean }, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#distinct */
|
||||
distinct(key: string, query: Object, callback: MongoCallback<any>): void;
|
||||
distinct(key: string, query: Object, options?: { readPreference?: ReadPreference | string, maxTimeMS?: number, session?: ClientSession }): Promise<any>;
|
||||
@@ -506,25 +506,25 @@ export interface Collection<TSchema = Default> {
|
||||
dropIndexes(callback?: MongoCallback<any>): void;
|
||||
dropIndexes(options: {session?: ClientSession, maxTimeMS?: number}, callback: MongoCallback<any>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#find */
|
||||
find<T = TSchema>(query?: Object): Cursor<T>;
|
||||
find<T = TSchema>(query?: FilterQuery<T>): Cursor<T>;
|
||||
/** @deprecated */
|
||||
find<T = TSchema>(query: Object, options?: FindOneOptions): Cursor<T>;
|
||||
find<T = TSchema>(query: FilterQuery<T>, options?: FindOneOptions): Cursor<T>;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#findOne */
|
||||
findOne<T = TSchema>(filter: Object, callback: MongoCallback<T | null>): void;
|
||||
findOne<T = TSchema>(filter: Object, options?: FindOneOptions): Promise<T | null>;
|
||||
findOne<T = TSchema>(filter: Object, options: FindOneOptions, callback: MongoCallback<T | null>): void;
|
||||
findOne<T = TSchema>(filter: FilterQuery<TSchema>, callback: MongoCallback<T | null>): void;
|
||||
findOne<T = TSchema>(filter: FilterQuery<TSchema>, options?: FindOneOptions): Promise<T | null>;
|
||||
findOne<T = TSchema>(filter: FilterQuery<TSchema>, options: FindOneOptions, callback: MongoCallback<T | null>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#findOneAndDelete */
|
||||
findOneAndDelete(filter: Object, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndDelete(filter: Object, options?: { projection?: Object, sort?: Object, maxTimeMS?: number, session?: ClientSession }): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
||||
findOneAndDelete(filter: Object, options: { projection?: Object, sort?: Object, maxTimeMS?: number, session?: ClientSession }, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndDelete(filter: FilterQuery<TSchema>, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndDelete(filter: FilterQuery<TSchema>, options?: { projection?: Object, sort?: Object, maxTimeMS?: number, session?: ClientSession }): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
||||
findOneAndDelete(filter: FilterQuery<TSchema>, options: { projection?: Object, sort?: Object, maxTimeMS?: number, session?: ClientSession }, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#findOneAndReplace */
|
||||
findOneAndReplace(filter: Object, replacement: Object, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndReplace(filter: Object, replacement: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
||||
findOneAndReplace(filter: Object, replacement: Object, options: FindOneAndReplaceOption, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndReplace(filter: FilterQuery<TSchema>, replacement: Object, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndReplace(filter: FilterQuery<TSchema>, replacement: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
||||
findOneAndReplace(filter: FilterQuery<TSchema>, replacement: Object, options: FindOneAndReplaceOption, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#findOneAndUpdate */
|
||||
findOneAndUpdate(filter: Object, update: Object, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndUpdate(filter: Object, update: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
||||
findOneAndUpdate(filter: Object, update: Object, options: FindOneAndReplaceOption, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndUpdate(filter: FilterQuery<TSchema>, update: Object, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
findOneAndUpdate(filter: FilterQuery<TSchema>, update: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
||||
findOneAndUpdate(filter: FilterQuery<TSchema>, update: Object, options: FindOneAndReplaceOption, callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#geoHaystackSearch */
|
||||
geoHaystackSearch(x: number, y: number, callback: MongoCallback<any>): void;
|
||||
geoHaystackSearch(x: number, y: number, options?: GeoHaystackSearchOptions): Promise<any>;
|
||||
@@ -602,9 +602,9 @@ export interface Collection<TSchema = Default> {
|
||||
rename(newName: string, options?: { dropTarget?: boolean, session?: ClientSession }): Promise<Collection<TSchema>>;
|
||||
rename(newName: string, options: { dropTarget?: boolean, session?: ClientSession }, callback: MongoCallback<Collection<TSchema>>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#replaceOne */
|
||||
replaceOne(filter: Object, doc: Object, callback: MongoCallback<ReplaceWriteOpResult>): void;
|
||||
replaceOne(filter: Object, doc: Object, options?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
|
||||
replaceOne(filter: Object, doc: Object, options: ReplaceOneOptions, callback: MongoCallback<ReplaceWriteOpResult>): void;
|
||||
replaceOne(filter: FilterQuery<TSchema>, doc: Object, callback: MongoCallback<ReplaceWriteOpResult>): void;
|
||||
replaceOne(filter: FilterQuery<TSchema>, doc: Object, options?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
|
||||
replaceOne(filter: FilterQuery<TSchema>, doc: Object, options: ReplaceOneOptions, callback: MongoCallback<ReplaceWriteOpResult>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#save */
|
||||
/** @deprecated Use insertOne, insertMany, updateOne or updateMany */
|
||||
save(doc: Object, callback: MongoCallback<WriteOpResult>): void;
|
||||
@@ -618,23 +618,62 @@ export interface Collection<TSchema = Default> {
|
||||
stats(options: { scale: number, session?: ClientSession }, callback: MongoCallback<CollStats>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#update */
|
||||
/** @deprecated use updateOne, updateMany or bulkWrite */
|
||||
update(filter: Object, update: Object, callback: MongoCallback<WriteOpResult>): void;
|
||||
update(filter: FilterQuery<TSchema>, update: Object, callback: MongoCallback<WriteOpResult>): void;
|
||||
/** @deprecated use updateOne, updateMany or bulkWrite */
|
||||
update(filter: Object, update: Object, options?: ReplaceOneOptions & { multi?: boolean }): Promise<WriteOpResult>;
|
||||
update(filter: FilterQuery<TSchema>, update: Object, options?: ReplaceOneOptions & { multi?: boolean }): Promise<WriteOpResult>;
|
||||
/** @deprecated use updateOne, updateMany or bulkWrite */
|
||||
update(filter: Object, update: Object, options: ReplaceOneOptions & { multi?: boolean }, callback: MongoCallback<WriteOpResult>): void;
|
||||
update(filter: FilterQuery<TSchema>, update: Object, options: ReplaceOneOptions & { multi?: boolean }, callback: MongoCallback<WriteOpResult>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#updateMany */
|
||||
updateMany(filter: Object, update: Object, callback: MongoCallback<UpdateWriteOpResult>): void;
|
||||
updateMany(filter: Object, update: Object, options?: CommonOptions & { upsert?: boolean }): Promise<UpdateWriteOpResult>;
|
||||
updateMany(filter: Object, update: Object, options: CommonOptions & { upsert?: boolean }, callback: MongoCallback<UpdateWriteOpResult>): void;
|
||||
updateMany(filter: FilterQuery<TSchema>, update: Object, callback: MongoCallback<UpdateWriteOpResult>): void;
|
||||
updateMany(filter: FilterQuery<TSchema>, update: Object, options?: CommonOptions & { upsert?: boolean }): Promise<UpdateWriteOpResult>;
|
||||
updateMany(filter: FilterQuery<TSchema>, update: Object, options: CommonOptions & { upsert?: boolean }, callback: MongoCallback<UpdateWriteOpResult>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#updateOne */
|
||||
updateOne(filter: Object, update: Object, callback: MongoCallback<UpdateWriteOpResult>): void;
|
||||
updateOne(filter: Object, update: Object, options?: ReplaceOneOptions): Promise<UpdateWriteOpResult>;
|
||||
updateOne(filter: Object, update: Object, options: ReplaceOneOptions, callback: MongoCallback<UpdateWriteOpResult>): void;
|
||||
updateOne(filter: FilterQuery<TSchema>, update: Object, callback: MongoCallback<UpdateWriteOpResult>): void;
|
||||
updateOne(filter: FilterQuery<TSchema>, update: Object, options?: ReplaceOneOptions): Promise<UpdateWriteOpResult>;
|
||||
updateOne(filter: FilterQuery<TSchema>, update: Object, options: ReplaceOneOptions, callback: MongoCallback<UpdateWriteOpResult>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#watch */
|
||||
watch(pipeline?: Object[], options?: ChangeStreamOptions & { session?: ClientSession }): ChangeStream;
|
||||
}
|
||||
|
||||
type FilterQuery<T> = {
|
||||
[P in keyof T]?: T[P] | {
|
||||
$eq?: T[P];
|
||||
$gt?: T[P];
|
||||
$gte?: T[P];
|
||||
$in?: T[P][];
|
||||
$lt?: T[P];
|
||||
$lte?: T[P];
|
||||
$ne?: T[P];
|
||||
$nin?: T[P][];
|
||||
$and?: (FilterQuery<T[P]> | T[P])[];
|
||||
$or?: (FilterQuery<T[P]> | T[P])[];
|
||||
$not?: (FilterQuery<T[P]> | T[P])[] | T[P];
|
||||
$expr?: any;
|
||||
$jsonSchema?: any;
|
||||
$mod?: [number, number];
|
||||
$regex?: RegExp;
|
||||
$options?: string;
|
||||
$text?: {
|
||||
$search: string;
|
||||
$language?: string;
|
||||
$caseSensitive?: boolean;
|
||||
$diacraticSensitive?: boolean;
|
||||
};
|
||||
$where: Object;
|
||||
$geoIntersects?: Object;
|
||||
$geoWithin?: Object;
|
||||
$near?: Object;
|
||||
$nearSphere?: Object;
|
||||
$elemMatch?: Object;
|
||||
$size?: number;
|
||||
$bitsAllClear?: Object;
|
||||
$bitsAllSet?: Object;
|
||||
$bitsAnyClear?: Object;
|
||||
$bitsAnySet?: Object;
|
||||
[key: string]: any;
|
||||
};
|
||||
} | { [key:string]: any };
|
||||
|
||||
// Documentation: http://docs.mongodb.org/manual/reference/command/collStats/
|
||||
export interface CollStats {
|
||||
// Namespace.
|
||||
|
||||
@@ -98,4 +98,19 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', options, function (err: mo
|
||||
type payment = typeof payment;
|
||||
let cursor: mongodb.AggregationCursor<payment> = collection.aggregate<payment>([{}])
|
||||
}
|
||||
|
||||
// test for new typings
|
||||
{
|
||||
type TestCollection = {
|
||||
stringField: string;
|
||||
numberField: number;
|
||||
};
|
||||
let testCollection = db.collection<TestCollection>('testCollection');
|
||||
|
||||
testCollection.find({
|
||||
numberField: {
|
||||
$and: [{ $gt: 0, $lt: 100 }]
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user