mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
add mongoose type file
This commit is contained in:
@@ -0,0 +1,366 @@
|
||||
/// <reference path="mongoose.d.ts" />
|
||||
|
||||
var fs = require('fs');
|
||||
import mongoose = require('mongoose');
|
||||
|
||||
var createInstance = new mongoose.Mongoose();
|
||||
|
||||
var Schema = mongoose.Schema;
|
||||
var CreateSchema = new Schema({});
|
||||
|
||||
mongoose.connect('mongodb://user:pass@localhost:port/database');
|
||||
mongoose.connect('mongodb://hostA:27501,hostB:27501', { mongos: true });
|
||||
|
||||
var conn: mongoose.Connection = mongoose.createConnection('mongodb://user:pass@localhost:port/database');
|
||||
conn = mongoose.createConnection('mongodb://user:pass@localhost:port/database,mongodb://anotherhost:port,mongodb://yetanother:port', { replset: { strategy: 'ping', rs_name: 'testSet' }});
|
||||
conn = mongoose.createConnection('localhost', 'database', 27014);
|
||||
conn = mongoose.createConnection('localhost', 'database', 27014, { server: { auto_reconnect: false }, user: 'username', pass: 'mypassword' });
|
||||
conn = mongoose.createConnection();
|
||||
conn.open('localhost', 'database', 27014, {});
|
||||
|
||||
var db = mongoose.createConnection();
|
||||
db.openSet("mongodb://user:pwd@localhost:27020/testing,mongodb://example.com:27020,mongodb://localhost:27019");
|
||||
db.openSet('mongodb://mongosA:27501,mongosB:27501', 'db', { mongos: true }, (err: any) => {});
|
||||
db.close();
|
||||
|
||||
var collection = db.collection('collection1');
|
||||
|
||||
mongoose.connection.on('error', (err: any) => {});
|
||||
mongoose.disconnect();
|
||||
|
||||
mongoose.set('test', 1234567890);
|
||||
var value = mongoose.get('test');
|
||||
mongoose.set('debug', true);
|
||||
|
||||
interface IActor extends mongoose.Document {
|
||||
name: string;
|
||||
}
|
||||
mongoose.model<IActor>('Actor', new Schema({ name: String }));
|
||||
db.model<IActor>('Actor', new Schema({ name: String }));
|
||||
var schema: mongoose.Schema = new Schema({ name: String }, { collection: 'actor' });
|
||||
schema.set('collection', 'actor');
|
||||
var Model = mongoose.model<IActor>('Actor', schema, 'actor');
|
||||
|
||||
var names: string[] = mongoose.modelNames();
|
||||
var names: string[] = db.modelNames();
|
||||
mongoose.plugin((schema: mongoose.Schema) => {
|
||||
}, { index: true });
|
||||
|
||||
|
||||
var aggregate = new mongoose.Aggregate();
|
||||
var aggregate = new mongoose.Aggregate({ $project: { a: 1, b: 1 } });
|
||||
var aggregate = new mongoose.Aggregate({ $project: { a: 1, b: 1 } }, { $skip: 5 });
|
||||
var aggregate = new mongoose.Aggregate([{ $project: { a: 1, b: 1 } }, { $skip: 5 }]);
|
||||
aggregate.append({ $project: { field: 1 }}, { $limit: 2 });
|
||||
aggregate.append([{ $match: { daw: 'Logic Audio X' }} ]);
|
||||
aggregate.group({ _id: "$department" });
|
||||
aggregate.skip(10);
|
||||
aggregate.limit(10);
|
||||
aggregate.match({ department: { $in: [ "sales", "engineering" ] } });
|
||||
aggregate.near({
|
||||
near: [40.724, -73.997],
|
||||
distanceField: "dist.calculated", // required
|
||||
maxDistance: 0.008,
|
||||
query: { type: "public" },
|
||||
includeLocs: "dist.location",
|
||||
uniqueDocs: true,
|
||||
num: 5
|
||||
});
|
||||
aggregate.project("a b -_id");
|
||||
aggregate.project({a: 1, b: 1, _id: 0});
|
||||
aggregate.project({
|
||||
newField: '$b.nested',
|
||||
plusTen: { $add: ['$val', 10]},
|
||||
sub: {
|
||||
name: '$a'
|
||||
}
|
||||
});
|
||||
aggregate.project({ salary_k: { $divide: [ "$salary", 1000 ] } });
|
||||
aggregate.sort({ field: 'asc', test: -1 });
|
||||
aggregate.sort('field -test');
|
||||
aggregate.unwind("tags");
|
||||
aggregate.unwind("a", "b", "c");
|
||||
var p = aggregate.exec();
|
||||
aggregate.read('primaryPreferred').exec((err: any, result: {}) => {});
|
||||
|
||||
|
||||
var p = new mongoose.Promise;
|
||||
var p2 = p.then(function() { throw new Error('shucks') }).end();
|
||||
setTimeout(function() {
|
||||
p.fulfill({});
|
||||
}, 10);
|
||||
var promise = new mongoose.Promise<number>();
|
||||
promise.then(function (meetups: number) {
|
||||
return new mongoose.Promise<string[]>();
|
||||
}).then(function (people: string[]) {
|
||||
if (people.length < 10000) {
|
||||
throw new Error('Too few people!!!');
|
||||
} else {
|
||||
throw new Error('Still need more people!!!');
|
||||
}
|
||||
}).then(null, function (err: Error) {
|
||||
}).end();
|
||||
|
||||
|
||||
Model.findOne({ name: 'john' }, (err: any, doc: mongoose.Document) => {
|
||||
doc.invalidate('size', 'must be less than 20', 14);
|
||||
doc.validate((err: any) => { });
|
||||
|
||||
doc.set('documents.0.title', 'changed');
|
||||
doc.get('documents.0');
|
||||
doc.set({
|
||||
'path' : 1,
|
||||
'path2' : {
|
||||
'path' : 2
|
||||
}
|
||||
});
|
||||
doc.set('path', 'value', { strict: false });
|
||||
doc.set('path3', '1', Number);
|
||||
doc.get('path3', Number);
|
||||
doc.id;
|
||||
doc._id;
|
||||
|
||||
doc.isModified();
|
||||
doc.isModified('documents');
|
||||
doc.isModified('documents.0.title');
|
||||
doc.isDirectModified('documents.0.title');
|
||||
doc.isDirectModified('documents');
|
||||
doc.isSelected('name');
|
||||
|
||||
doc.markModified('mixed.type');
|
||||
doc.populate('user');
|
||||
doc.populate('other', (err: any, doc: mongoose.Document) => {});
|
||||
doc.populated('author');
|
||||
doc.save();
|
||||
|
||||
doc.toJSON({ getters: true, virtuals: false });
|
||||
var data: any = doc.toObject();
|
||||
delete data['age'];
|
||||
delete data['weight'];
|
||||
data['isAwesome'] = true;
|
||||
});
|
||||
|
||||
Model.model('User').findById('id', (err: any, res: IActor) => {});
|
||||
Model.count({ type: 'jungle' }, (err: any, count: number) => {});
|
||||
Model.remove((err: any, res: IActor[]) => {});
|
||||
Model.save((err: any, res: IActor, numberAffected: number) => {});
|
||||
Model.create({ type: 'jelly bean' }, { type: 'snickers' }, (err: any, res1: IActor, res2: IActor) => {});
|
||||
Model.create({ type: 'jawbreaker' });
|
||||
Model.distinct('url', { clicks: {$gt: 100}}, (err: any, result: IActor[]) => {});
|
||||
Model.distinct('url');
|
||||
|
||||
Model.aggregate(
|
||||
{ $group: { _id: null, maxBalance: { $max: '$balance' }}},
|
||||
{ $project: { _id: 0, maxBalance: 1 }},
|
||||
(err: any, res: IActor[]) => {});
|
||||
Model.aggregate()
|
||||
.group({ _id: null, maxBalance: { $max: '$balance' } })
|
||||
.select('-id maxBalance')
|
||||
.exec((err: any, res: IActor[]) => {});
|
||||
Model.ensureIndexes((err) => {});
|
||||
|
||||
Model.find({ name: 'john', age: { $gte: 18 }});
|
||||
Model.find({ name: 'john', age: { $gte: 18 }}, (err: any, docs: IActor[]) => {});
|
||||
Model.find({ name: /john/i }, 'name friends', (err: any, docs: IActor[]) => {});
|
||||
Model.find({ name: /john/i }, null, { skip: 10 });
|
||||
Model.find({ name: /john/i }, null, { skip: 10 }, (err: any, docs: IActor[]) => {});
|
||||
Model.find({ name: /john/i }, null, { skip: 10 }).exec((err: any, docs: IActor[]) => {});
|
||||
var query = Model.find({ name: /john/i }, null, { skip: 10 });
|
||||
var promise1 = query.exec();
|
||||
promise1.addBack((err: any, docs: IActor[]) => {});
|
||||
|
||||
Model.findById('id', (err: any, res: IActor) => {});
|
||||
Model.findById('id').exec((err: any, res: IActor) => {});
|
||||
Model.findById('id', 'name length', (err: any, res: IActor) => {});
|
||||
Model.findById('id', '-length').exec((err: any, res: IActor) => {});
|
||||
Model.findById('id', 'name', { lean: true }, (err: any, res: IActor) => {});
|
||||
Model.findById('id', 'name').lean().exec((err: any, res: IActor) => {});
|
||||
Model.findByIdAndRemove('id1', { select: 'name' }, (err: any, res: IActor) => {});
|
||||
Model.findByIdAndRemove('id1', { select: 'name' }).exec((err: any, res: IActor) => {});
|
||||
Model.findByIdAndRemove('id1', (err: any, res: IActor) => {});
|
||||
Model.findByIdAndRemove('id1').exec((err: any, res: IActor) => {});
|
||||
Model.findByIdAndUpdate('id2', { $set: { name: 'jason borne' }}, { upsert: true }, (err: any, res: IActor) => {});
|
||||
|
||||
Model.findOne({ type: 'iphone' }, (err: any, res: IActor) => {});
|
||||
Model.findOne({ type: 'iphone' }).exec((err: any, res: IActor) => {});
|
||||
Model.findOne({ type: 'iphone' }, 'name', (err: any, res: IActor) => {});
|
||||
Model.findOne({ type: 'iphone' }, 'name').exec((err: any, res: IActor) => {});
|
||||
Model.findOne({ type: 'iphone' }, 'name', { lean: true }, (err: any, res: IActor) => {});
|
||||
Model.findOne({ type: 'iphone' }, 'name', { lean: true }).exec((err: any, res: IActor) => {});
|
||||
Model.findOne({ type: 'iphone' }).select('name').lean().exec((err: any, res: IActor) => {});
|
||||
Model.findOneAndRemove({ type: 'iphone' }, { select: 'name' }, (err: any, res: IActor) => {});
|
||||
Model.findOneAndRemove({ type: 'iphone' }, { select: 'name' }).exec((err: any, res: IActor) => {});
|
||||
Model.findOneAndUpdate({ type: 'iphone' }, { $set: { name: 'jason borne' }}, { upsert: true }, (err: any, res: IActor) => {});
|
||||
|
||||
Model.geoNear([1, 3], { maxDistance : 5, spherical : true }, (err: any, res: IActor[]) => {});
|
||||
Model.geoNear({ type : "Point", coordinates : [9,9] }, { maxDistance : 5, spherical : true }, (err: any, res: IActor[]) => {});
|
||||
Model.geoSearch({ type : "house" }, { near: [10, 10], maxDistance: 5 }, (err: any, res: IActor[]) => {});
|
||||
|
||||
var o = {
|
||||
map: function () { this.emit(this.name, 1) },
|
||||
reduce: function (k: string, vals: IActor[]) { return vals.length },
|
||||
};
|
||||
Model.mapReduce(o, (err: any, res: any[]) => {});
|
||||
|
||||
Model.findById('id', (err: any, res: IActor) => {
|
||||
var opts = [
|
||||
{ path: 'company', match: { x: 1 }, select: 'name' },
|
||||
{ path: 'notes', options: { limit: 10 }, model: 'override' }
|
||||
];
|
||||
Model.populate(res, opts, (err: any, res: IActor) => {});
|
||||
});
|
||||
Model.find({ type: 'iphone' }, (err: any, res: IActor[]) => {
|
||||
var opts = [{ path: 'company', match: { x: 1 }, select: 'name' }];
|
||||
var promise = Model.populate(res, opts);
|
||||
promise.then(console.log).end();
|
||||
});
|
||||
Model.populate({ name: 'Test A' }, { path: 'weapon', model: 'Weapon' }, (err: any, user: IActor) => {});
|
||||
Model.populate([
|
||||
{ name: 'User hoge' },
|
||||
{ name: 'User fuga' },
|
||||
], { path: 'weapon' }, (err: any, users: IActor[]) => {});
|
||||
|
||||
Model.remove({ title: 'baby born from alien father' }, (err: any) => {});
|
||||
var query2 = Model.remove({ _id: 'id' });
|
||||
query2.exec();
|
||||
Model.update({ age: { $gt: 18 } }, { oldEnough: true }, (err: any, numberAffected: number, raw: any) => {});
|
||||
Model.update({ name: 'Tobi' }, { ferret: true }, { multi: true }, (err: any, numberAffected: number, raw: any) => {});
|
||||
Model.update({ _id: 'id' }, { $set: { text: 'changed' }}).exec();
|
||||
|
||||
Model.where('age').gte(21).lte(65).exec((err: any, res: IActor[]) => {});
|
||||
var query3 =Model
|
||||
.where('age').gt(21).lt(65)
|
||||
.where('name', /^b/i).all('type', 1);
|
||||
query3.all(25);
|
||||
query3.and([{ color: 'green' }, { status: 'ok' }]);
|
||||
query3.batchSize(100);
|
||||
query3.where('loc').within().box([40.73083, -73.99756], [40.741404, -73.988135]);
|
||||
query3.where('loc').within().circle({ center: [50, 50], radius: 10, unique: true });
|
||||
query3.circle('loc', { center: [50, 50], radius: 10, unique: true });
|
||||
query3.comment('login query');
|
||||
query3.where({ 'color': 'black' }).count();
|
||||
query3.count({ color: 'black' }).count((err: any, count: number) => {});
|
||||
query3.count({ color: 'black' }, (err: any, count: number) => {});
|
||||
query3.where({ color: 'black' }).count((err: any, count: number) => {});
|
||||
query3.elemMatch('comment', { author: 'autobot', votes: {$gte: 5}});
|
||||
query3.where('comment').elemMatch({ author: 'autobot', votes: {$gte: 5}});
|
||||
query.elemMatch('comment', (elem: mongoose.Query<IActor>) => {
|
||||
elem.where('author').equals('autobot');
|
||||
elem.where('votes').gte(5);
|
||||
});
|
||||
query3.where('age').equals(49);
|
||||
query3.where('age', 49);
|
||||
query3.exec();
|
||||
query3.exec('update');
|
||||
query3.where('name').exists();
|
||||
query3.where('name').exists(true);
|
||||
query3.find().exists('name');
|
||||
query3.where('name').exists(false);
|
||||
query3.find().exists('name', false);
|
||||
query3.find({ name: 'Los Pollos Hermanos' }).find((err: any, res: IActor[]) => {});
|
||||
query3.where('loc').within().geometry({ type: 'Polygon', coordinates: [[[ 10, 20 ], [ 10, 40 ], [ 30, 40 ], [ 30, 20 ]]] });
|
||||
query3.find().where('age').gt(21);
|
||||
query3.find().gt('age', 21);
|
||||
query3.hint({ indexA: 1, indexB: -1});
|
||||
query3.where('path').intersects().geometry({ type: 'LineString', coordinates: [[180.0, 11.0], [180, 9.0]] });
|
||||
query3.where('path').intersects({ type: 'LineString', coordinates: [[180.0, 11.0], [180, 9.0]] });
|
||||
query3.maxScan(100);
|
||||
query3.where('loc').near({ center: [10, 10] });
|
||||
query3.where('loc').near({ center: [10, 10], maxDistance: 5 });
|
||||
query3.where('loc').near({ center: [10, 10], maxDistance: 5, spherical: true });
|
||||
query3.near('loc', { center: [10, 10], maxDistance: 5 });
|
||||
query3.where('loc').nearSphere({ center: [10, 10], maxDistance: 5 });
|
||||
query3.nor([{ color: 'green' }, { status: 'ok' }]);
|
||||
query3.or([{ color: 'red' }, { status: 'emergency' }]);
|
||||
query3.where('loc').within().polygon([10,20], [13, 25], [7,15]);
|
||||
query3.polygon('loc', [10,20], [13, 25], [7,15]);
|
||||
|
||||
query3.findOne().populate('owner').exec((err: any, res: IActor[]) => {});
|
||||
query3.find().populate({
|
||||
path: 'owner',
|
||||
select: 'name',
|
||||
match: { color: 'black' },
|
||||
options: { sort: { name: -1 }}
|
||||
}).exec((err: any, res: IActor[]) => {});
|
||||
query3.find().populate('owner', 'name', null, {sort: { name: -1 }}).exec((err: any, res: IActor[]) => {});
|
||||
|
||||
query3.read('primary');
|
||||
query3.read('p');
|
||||
query3.read('primaryPreferred');
|
||||
query3.read('pp');
|
||||
query3.read('secondary');
|
||||
query3.read('s');
|
||||
query3.read('secondaryPreferred');
|
||||
query3.read('sp');
|
||||
query3.read('nearest');
|
||||
query3.read('n');
|
||||
query3.read('s', [{ dc:'sf', s: 1 },{ dc:'ma', s: 2 }]);
|
||||
query3.remove({ artist: 'Anne Murray' }, (err: any, res: IActor[]) => {});
|
||||
query3.select('a b -c');
|
||||
query3.select({a: 1, b: 1, c: 0});
|
||||
query3.select('+path');
|
||||
query3.where('tags').size(0);
|
||||
query3.skip(100).limit(20);
|
||||
query3.slaveOk();
|
||||
query3.slaveOk(true);
|
||||
query3.slaveOk(false);
|
||||
query3.slice('comments', -5);
|
||||
query3.slice('comments', [10, 5])
|
||||
query3.where('comments').slice(5);
|
||||
query3.where('comments').slice([-10, 5]);
|
||||
query3.snapshot();
|
||||
query3.snapshot(true);
|
||||
query3.snapshot(false);
|
||||
query3.sort({ field: 'asc', test: -1 });
|
||||
query3.sort('field -test');
|
||||
Model.find({ name: /^hello/ }).stream({ transform: JSON.stringify }).pipe(fs.createWriteStream('./test.json'));
|
||||
var stream = Model.find({ name: /^hello/ }).stream();
|
||||
stream
|
||||
.on('data', (doc: IActor) => {})
|
||||
.on('error', (err: any) => {})
|
||||
.on('close', () => {});
|
||||
|
||||
query3.tailable();
|
||||
query3.tailable(false);
|
||||
var AdvQuery = query3.toConstructor();
|
||||
query3.update({ title: 'words' });
|
||||
query3.update({ $set: { title: 'words' }});
|
||||
query3.update({ name: /^match/ }, { $set: { arr: [] }}, { multi: true }, (err: any, row: number, raw: any) => {});
|
||||
|
||||
query3.where('loc').within({ center: [50,50], radius: 10, unique: true, spherical: true });
|
||||
query3.where('loc').within({ box: [[40.73, -73.9], [40.7, -73.988]] });
|
||||
query3.where('loc').within({ polygon: [[],[],[],[]] });
|
||||
query3.where('loc').within([], [], []); // polygon
|
||||
query3.where('loc').within([], []); // box
|
||||
query3.where('loc').within({ type: 'LineString', coordinates: [] }); // geometry
|
||||
|
||||
mongoose.Query.use$geoWithin = false;
|
||||
|
||||
|
||||
var ToySchema = new Schema({});
|
||||
ToySchema.add({ name: 'string', color: 'string', price: 'number' });
|
||||
schema.eachPath(function(path: string, value: any) {});
|
||||
schema.index({ first: 1, last: -1 });
|
||||
schema.indexes();
|
||||
schema.method('meow', function() {
|
||||
console.log('meeeeeoooooooooooow');
|
||||
});
|
||||
var Kitty = mongoose.model<IActor>('Kitty', schema);
|
||||
var fizz: any = new Kitty({ name: 'kitty' });
|
||||
fizz.meow();
|
||||
schema.method({
|
||||
purr: function() {},
|
||||
scratch: function() {},
|
||||
});
|
||||
schema.path('name');
|
||||
schema.path('name', Number);
|
||||
schema.pathType('name');
|
||||
schema.plugin(function() {});
|
||||
schema.post('save', function(doc: IActor) {});
|
||||
schema.pre('save', function(next: () => void) {});
|
||||
schema.requiredPaths();
|
||||
schema.static('findByName', function(name: string, callback: () => void) {});
|
||||
schema.virtual('display_name')
|
||||
.get(function(): string { return this.name; })
|
||||
.set((value: string): void => {});
|
||||
|
||||
Vendored
+453
@@ -0,0 +1,453 @@
|
||||
// Type definitions for Mongoose 3.8.5
|
||||
// Project: http://mongoosejs.com/
|
||||
// Definitions by: horiuchi <https://github.com/horiuchi/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
///<reference path="../node/node.d.ts" />
|
||||
|
||||
declare module "mongoose" {
|
||||
function connect(uri: string, options?: ConnectionOption, callback?: (err: any) => void): Mongoose;
|
||||
function createConnection(): Connection;
|
||||
function createConnection(uri: string, options?: ConnectionOption): Connection;
|
||||
function createConnection(host: string, database_name: string, port?: number, options?: ConnectionOption): Connection;
|
||||
function disconnect(callback?: (err?: any) => void): Mongoose;
|
||||
|
||||
function model<T extends Document>(name: string, schema: Schema, collection?: string, skipInit?: boolean): Model<T>;
|
||||
function modelNames(): string[];
|
||||
function plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Mongoose;
|
||||
|
||||
function get(key: string): any;
|
||||
function set(key: string, value: any): void;
|
||||
|
||||
var mongo: any;
|
||||
var mquery: any;
|
||||
var version: string;
|
||||
var connection: Connection;
|
||||
|
||||
export class Mongoose {
|
||||
connect(uri: string, options?: ConnectionOption, callback?: (err: any) => void): Mongoose;
|
||||
createConnection(): Connection;
|
||||
createConnection(uri: string, options?: Object): Connection;
|
||||
createConnection(host: string, database_name: string, port?: number, options?: ConnectionOption): Connection;
|
||||
disconnect(callback?: (err?: any) => void): Mongoose;
|
||||
get(key: string): any;
|
||||
model<T extends Document>(name: string, schema: Schema, collection?: string, skipInit?: boolean): Model<T>;
|
||||
modelNames(): string[];
|
||||
plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Mongoose;
|
||||
set(key: string, value: any): void;
|
||||
|
||||
mongo: any;
|
||||
mquery: any;
|
||||
version: string;
|
||||
connection: Connection;
|
||||
}
|
||||
|
||||
export interface Connection extends NodeJS.EventEmitter {
|
||||
constructor(base: Mongoose): Connection;
|
||||
|
||||
close(callback?: (err: any) => void): Connection;
|
||||
collection(name: string, options?: Object): Collection;
|
||||
model<T extends Document>(name: string, schema: Schema, collection?: string): Model<T>;
|
||||
modelNames(): string[];
|
||||
open(host: string, database?: string, port?: number, options?: ConnectionOption, callback?: (err: any) => void): Connection;
|
||||
openSet(uris: string, database?: string, options?: ConnectionSetOption, callback?: (err: any) => void): Connection;
|
||||
|
||||
db: any;
|
||||
collections: {[index: string]: Collection};
|
||||
readyState: number;
|
||||
}
|
||||
export interface ConnectionOption {
|
||||
db?: any;
|
||||
server?: any;
|
||||
replset?: any;
|
||||
user?: string;
|
||||
pass?: string;
|
||||
auth?: any;
|
||||
}
|
||||
export interface ConnectionSetOption extends ConnectionOption {
|
||||
mongos?: boolean;
|
||||
}
|
||||
|
||||
export interface Collection {
|
||||
}
|
||||
|
||||
|
||||
export class SchemaType { }
|
||||
export class VirtualType {
|
||||
get(fn: Function): VirtualType;
|
||||
set(fn: Function): VirtualType;
|
||||
}
|
||||
export module Types {
|
||||
export class ObjectId {}
|
||||
}
|
||||
|
||||
export class Schema {
|
||||
static Types: {
|
||||
String: String;
|
||||
ObjectId: Types.ObjectId;
|
||||
OId: Types.ObjectId;
|
||||
Mixed: any;
|
||||
};
|
||||
constructor(schema?: Object, options?: Object);
|
||||
|
||||
add(obj: Object, prefix?: string): void;
|
||||
eachPath(fn: (path: string, type: any) => void): Schema;
|
||||
get(key: string): any;
|
||||
index(fields: Object, options?: Object): Schema;
|
||||
indexes(): void;
|
||||
method(name: string, fn: Function): Schema;
|
||||
method(method: Object): Schema;
|
||||
path(path: string): any;
|
||||
path(path: string, constructor: any): Schema;
|
||||
pathType(path: string): string;
|
||||
plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Schema;
|
||||
post(method: string, fn: Function): Schema;
|
||||
pre(method: string, callback: Function): Schema;
|
||||
requiredPaths(): string[];
|
||||
set(key: string, value: any): void;
|
||||
static(name: string, fn: Function): Schema;
|
||||
virtual(name: string, options?: Object): VirtualType;
|
||||
virtualpath(name: string): VirtualType;
|
||||
}
|
||||
export interface SchemaOption {
|
||||
autoIndex?: boolean;
|
||||
bufferCommands?: boolean;
|
||||
capped?: boolean;
|
||||
collection?: string;
|
||||
id?: boolean;
|
||||
_id?: boolean;
|
||||
minimize?: boolean;
|
||||
read?: string;
|
||||
safe?: boolean;
|
||||
shardKey?: boolean;
|
||||
strict?: boolean;
|
||||
toJSON?: Object;
|
||||
toObject?: Object;
|
||||
versionKey?: boolean;
|
||||
}
|
||||
|
||||
export interface Model<T extends Document> {
|
||||
new(doc: Object): T;
|
||||
|
||||
aggregate(...aggregations: Object[]): Aggregate<T[]>;
|
||||
aggregate(aggregation: Object, callback: (err: any, res: T[]) => void): Promise<T[]>;
|
||||
aggregate(aggregation1: Object, aggregation2: Object, callback: (err: any, res: T[]) => void): Promise<T[]>;
|
||||
aggregate(aggregation1: Object, aggregation2: Object, aggregation3: Object, callback: (err: any, res: T[]) => void): Promise<T[]>;
|
||||
count(conditions: Object, callback?: (err: any, count: number) => void): Query<number>;
|
||||
|
||||
create(doc: Object, fn?: (err: any, res: T) => void): Promise<T[]>;
|
||||
create(doc1: Object, doc2: Object, fn?: (err: any, res1: T, res2: T) => void): Promise<T[]>;
|
||||
create(doc1: Object, doc2: Object, doc3: Object, fn?: (err: any, res1: T, res2: T, res3: T) => void): Promise<T[]>;
|
||||
discriminator<U extends Document>(name: string, schema: Schema): Model<U>;
|
||||
distinct(field: string, callback?: (err: any, res: T[]) => void): Query<T[]>;
|
||||
distinct(field: string, conditions: Object, callback?: (err: any, res: T[]) => void): Query<T[]>;
|
||||
ensureIndexes(callback: (err: any) => void): Promise<T>;
|
||||
|
||||
find(cond: Object, callback?: (err: any, res: T[]) => void): Query<T[]>;
|
||||
find(cond: Object, fields: Object, callback?: (err: any, res: T[]) => void): Query<T[]>;
|
||||
find(cond: Object, fields: Object, options: Object, callback?: (err: any, res: T[]) => void): Query<T[]>;
|
||||
findById(id: string, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findById(id: string, fields: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findById(id: string, fields: Object, options: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findByIdAndRemove(id: string, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findByIdAndRemove(id: string, options: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findByIdAndUpdate(id: string, update: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findByIdAndUpdate(id: string, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOne(cond: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOne(cond: Object, fields: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOne(cond: Object, fields: Object, options: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndRemove(cond: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndRemove(cond: Object, options: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndUpdate(cond: Object, update: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndUpdate(cond: Object, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query<T>;
|
||||
|
||||
geoNear(point: { type: string; coordinates: number[] }, options: Object, callback?: (err: any, res: T[]) => void): Query<T[]>;
|
||||
geoNear(point: number[], options: Object, callback?: (err: any, res: T[]) => void): Query<T[]>;
|
||||
geoSearch(cond: Object, options: GeoSearchOption, callback?: (err: any, res: T[]) => void): Query<T[]>;
|
||||
increment(): T;
|
||||
mapReduce<K, V>(options: MapReduceOption<T, K, V>, callback?: (err: any, res: MapReduceResult<K, V>[]) => void): Promise<MapReduceResult<K, V>[]>;
|
||||
mapReduce<K, V>(options: MapReduceOption2<T, K, V>, callback?: (err: any, res: MapReduceResult<K, V>[]) => void): Promise<MapReduceResult<K, V>[]>;
|
||||
model<U extends Document>(name: string): Model<U>;
|
||||
|
||||
populate<U>(doc: U, options: Object, callback?: (err: any, res: U) => void): Promise<U>;
|
||||
populate<U>(doc: U[], options: Object, callback?: (err: any, res: U[]) => void): Promise<U[]>;
|
||||
update(cond: Object, update: Object, callback?: (err: any, affectedRows: number, raw: any) => void): Query<T>;
|
||||
update(cond: Object, update: Object, options: Object, callback?: (err: any, affectedRows: number, raw: any) => void): Query<T>;
|
||||
remove(cond: Object, callback?: (err: any) => void): Query<{}>;
|
||||
save(callback?: (err: any, result: T, numberAffected: number) => void): Query<T>;
|
||||
where(path: string, val?: Object): Query<T[]>;
|
||||
|
||||
$where(argument: string): Query<T>;
|
||||
$where(argument: Function): Query<T>;
|
||||
|
||||
base: Mongoose;
|
||||
collection: Collection;
|
||||
db: any;
|
||||
discriminators: any;
|
||||
modelName: string;
|
||||
schema: Schema;
|
||||
}
|
||||
export interface FindAndUpdateOption {
|
||||
new?: boolean;
|
||||
upsert?: boolean;
|
||||
sort?: Object;
|
||||
select?: Object;
|
||||
}
|
||||
export interface GeoSearchOption {
|
||||
near: number[];
|
||||
maxDistance: number;
|
||||
limit?: number;
|
||||
lean?: boolean;
|
||||
}
|
||||
export interface MapReduceOption<T extends Document, Key, Val> {
|
||||
map: () => void;
|
||||
reduce: (key: Key, vals: T[]) => Val;
|
||||
query?: Object;
|
||||
limit?: number;
|
||||
keeptemp?: boolean;
|
||||
finalize?: (key: Key, val: Val) => Val;
|
||||
scope?: Object;
|
||||
jsMode?: boolean;
|
||||
verbose?: boolean;
|
||||
out?: {
|
||||
inline?: number;
|
||||
replace?: string;
|
||||
reduce?: string;
|
||||
merge?: string;
|
||||
};
|
||||
}
|
||||
export interface MapReduceOption2<T extends Document, Key, Val> {
|
||||
map: string;
|
||||
reduce: (key: Key, vals: T[]) => Val;
|
||||
query?: Object;
|
||||
limit?: number;
|
||||
keeptemp?: boolean;
|
||||
finalize?: (key: Key, val: Val) => Val;
|
||||
scope?: Object;
|
||||
jsMode?: boolean;
|
||||
verbose?: boolean;
|
||||
out?: {
|
||||
inline?: number;
|
||||
replace?: string;
|
||||
reduce?: string;
|
||||
merge?: string;
|
||||
};
|
||||
}
|
||||
export interface MapReduceResult<Key, Val> {
|
||||
_id: Key;
|
||||
value: Val;
|
||||
}
|
||||
|
||||
export class Query<T> {
|
||||
exec(callback?: (err: any, res: T) => void): Promise<T>;
|
||||
exec(operation: string, callback?: (err: any, res: T) => void): Promise<T>;
|
||||
exec(operation: Function, callback?: (err: any, res: T) => void): Promise<T>;
|
||||
|
||||
all(val: number): Query<T>;
|
||||
all(path: string, val: number): Query<T>;
|
||||
and(array: Object[]): Query<T>;
|
||||
box(val: Object): Query<T>;
|
||||
box(a: number[], b: number[]): Query<T>;
|
||||
batchSize(val: number): Query<T>;
|
||||
cast<U extends Document>(model: Model<U>, obj: Object): U;
|
||||
//center(): Query<T>;
|
||||
//centerSphere(path: string, val: Object): Query<T>;
|
||||
circle(area: Object): Query<T>;
|
||||
circle(path: string, area: Object): Query<T>;
|
||||
comment(val: any): Query<T>;
|
||||
count(callback?: (err: any, count: number) => void): Query<T>;
|
||||
count(criteria: Object, callback?: (err: any, count: number) => void): Query<T>;
|
||||
distinct(callback?: (err: any, res: T) => void): Query<T>;
|
||||
distinct(field: string, callback?: (err: any, res: T) => void): Query<T>;
|
||||
distinct(criteria: Object, field: string, callback?: (err: any, res: T) => void): Query<T>;
|
||||
distinct(criteria: Query<T>, field: string, callback?: (err: any, res: T) => void): Query<T>;
|
||||
elemMatch(criteria: Object): Query<T>;
|
||||
elemMatch(criteria: (elem: Query<T>) => void): Query<T>;
|
||||
elemMatch(path: string, criteria: Object): Query<T>;
|
||||
elemMatch(path: string, criteria: (elem: Query<T>) => void): Query<T>;
|
||||
equals(val: Object): Query<T>;
|
||||
exists(val?: boolean): Query<T>;
|
||||
exists(path: string, val?: boolean): Query<T>;
|
||||
find(callback?: (err: any, res: T) => void): Query<T>;
|
||||
find(criteria: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOne(callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOne(criteria: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndRemove(callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndRemove(cond: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndRemove(cond: Object, options: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndUpdate(callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndUpdate(update: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndUpdate(cond: Object, update: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
findOneAndUpdate(cond: Object, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query<T>;
|
||||
geometry(object: Object): Query<T>;
|
||||
gt(val: number): Query<T>;
|
||||
gt(path: string, val: number): Query<T>;
|
||||
gte(val: number): Query<T>;
|
||||
gte(path: string, val: number): Query<T>;
|
||||
hint(val: Object): Query<T>;
|
||||
in(val: any[]): Query<T>;
|
||||
in(path: string, val: any[]): Query<T>;
|
||||
intersects(arg?: Object): Query<T>;
|
||||
lean(bool?: boolean): Query<T>;
|
||||
limit(val: number): Query<T>;
|
||||
lt(val: number): Query<T>;
|
||||
lt(path: string, val: number): Query<T>;
|
||||
lte(val: number): Query<T>;
|
||||
lte(path: string, val: number): Query<T>;
|
||||
maxDistance(val: number): Query<T>;
|
||||
maxDistance(path: string, val: number): Query<T>;
|
||||
maxScan(val: number): Query<T>;
|
||||
merge(source: Query<T>): Query<T>;
|
||||
merge(source: Object): Query<T>;
|
||||
mod(val: number[]): Query<T>;
|
||||
mod(path: string, val: number[]): Query<T>;
|
||||
ne(val: any): Query<T>;
|
||||
ne(path: string, val: any): Query<T>;
|
||||
near(val: Object): Query<T>;
|
||||
near(path: string, val: Object): Query<T>;
|
||||
nearSphere(val: Object): Query<T>;
|
||||
nearSphere(path: string, val: Object): Query<T>;
|
||||
nin(val: any[]): Query<T>;
|
||||
nin(path: string, val: any[]): Query<T>;
|
||||
nor(array: Object[]): Query<T>;
|
||||
or(array: Object[]): Query<T>;
|
||||
polygon(...coordinatePairs: number[][]): Query<T>;
|
||||
polygon(path: string, ...coordinatePairs: number[][]): Query<T>;
|
||||
populate(path: string, select?: string, match?: Object, options?: Object): Query<T>;
|
||||
populate(path: string, select: string, model: string, match?: Object, options?: Object): Query<T>;
|
||||
populate(opt: PopulateOption): Query<T>;
|
||||
read(pref: string, tags?: Object[]): Query<T>;
|
||||
regex(val: RegExp): Query<T>;
|
||||
regex(path: string, val: RegExp): Query<T>;
|
||||
remove(callback?: (err: any, res: T) => void): Query<T>;
|
||||
remove(criteria: Object, callback?: (err: any, res: T) => void): Query<T>;
|
||||
select(arg: string): Query<T>;
|
||||
select(arg: Object): Query<T>;
|
||||
setOptions(options: Object): Query<T>;
|
||||
size(val: number): Query<T>;
|
||||
size(path: string, val: number): Query<T>;
|
||||
skip(val: number): Query<T>;
|
||||
slaveOk(v?: boolean): Query<T>;
|
||||
slice(val: number): Query<T>;
|
||||
slice(val: number[]): Query<T>;
|
||||
slice(path: string, val: number): Query<T>;
|
||||
slice(path: string, val: number[]): Query<T>;
|
||||
snapshot(v?: boolean): Query<T>;
|
||||
sort(arg: Object): Query<T>;
|
||||
sort(arg: string): Query<T>;
|
||||
stream(options?: { transform?: Function; }): QueryStream;
|
||||
tailable(v?: boolean): Query<T>;
|
||||
toConstructor(): Query<T>;
|
||||
update(callback?: (err: any, affectedRows: number, doc: T) => void): Query<T>;
|
||||
update(doc: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query<T>;
|
||||
update(criteria: Object, doc: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query<T>;
|
||||
update(criteria: Object, doc: Object, options: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query<T>;
|
||||
where(path?: string, val?: any): Query<T>;
|
||||
where(path?: Object, val?: any): Query<T>;
|
||||
within(val?: Object): Query<T>;
|
||||
within(coordinate: number[], ...coordinatePairs: number[][]): Query<T>;
|
||||
|
||||
$where(argument: string): Query<T>;
|
||||
$where(argument: Function): Query<T>;
|
||||
|
||||
static use$geoWithin: boolean;
|
||||
}
|
||||
|
||||
export interface PopulateOption {
|
||||
path: string;
|
||||
select?: string;
|
||||
model?: string;
|
||||
match?: Object;
|
||||
options?: Object;
|
||||
}
|
||||
|
||||
export interface QueryStream extends NodeJS.EventEmitter {
|
||||
destory(err?: any): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
|
||||
paused: number;
|
||||
readable: boolean;
|
||||
}
|
||||
|
||||
export interface Document {
|
||||
id?: string;
|
||||
_id: string;
|
||||
|
||||
equals(doc: Document): boolean;
|
||||
get(path: string, type?: new(...args: any[]) => any): any;
|
||||
inspect(options?: Object): string;
|
||||
invalidate(path: string, errorMsg: string, value: any): void;
|
||||
invalidate(path: string, error: Error, value: any): void;
|
||||
isDirectModified(path: string): boolean;
|
||||
isInit(path: string): boolean;
|
||||
isModified(path?: string): boolean;
|
||||
isSelected(path: string): boolean;
|
||||
markModified(path: string): void;
|
||||
modifiedPaths(): string[];
|
||||
populate<T>(callback?: (err: any, res: T) => void): Document;
|
||||
populate<T>(path?: string, callback?: (err: any, res: T) => void): Document;
|
||||
populate<T>(opt: PopulateOption, callback?: (err: any, res: T) => void): Document;
|
||||
populated(path: string): any;
|
||||
remove<T>(callback?: (err: any) => void): Query<T>;
|
||||
save<T>(callback?: (err: any, res: T) => void): void;
|
||||
set(path: string, val: any, type?: new(...args: any[]) => any, options?: Object): void;
|
||||
set(path: string, val: any, options?: Object): void;
|
||||
set(value: Object): void;
|
||||
toJSON(options?: Object): Object;
|
||||
toObject(options?: Object): Object;
|
||||
toString(): string;
|
||||
update<T>(doc: Object, options: Object, callback: (err: any, affectedRows: number, raw: any) => void): Query<T>;
|
||||
validate(cb: (err: any) => void): void;
|
||||
|
||||
isNew: boolean;
|
||||
errors: Object;
|
||||
schema: Object;
|
||||
}
|
||||
|
||||
|
||||
export class Aggregate<T> {
|
||||
constructor(...options: Object[]);
|
||||
|
||||
append(...options: Object[]): Aggregate<T>;
|
||||
group(arg: Object): Aggregate<T>;
|
||||
limit(num: number): Aggregate<T>;
|
||||
match(arg: Object): Aggregate<T>;
|
||||
near(parameters: Object): Aggregate<T>;
|
||||
project(arg: string): Aggregate<T>;
|
||||
project(arg: Object): Aggregate<T>;
|
||||
select(filter: string): Aggregate<T>;
|
||||
skip(num: number): Aggregate<T>;
|
||||
sort(arg: string): Aggregate<T>;
|
||||
sort(arg: Object): Aggregate<T>;
|
||||
unwind(fiels: string, ...rest: string[]): Aggregate<T>;
|
||||
|
||||
exec(callback?: (err: any, result: T) => void): Promise<T>;
|
||||
read(pref: string, ...tags: Object[]): Aggregate<T>;
|
||||
}
|
||||
|
||||
export class Promise<T> {
|
||||
constructor(fn?: (err: any, result: T) => void);
|
||||
|
||||
then<U>(onFulFill: (result: T) => void, onReject?: (err: any) => void): Promise<U>;
|
||||
end(): void;
|
||||
|
||||
fulfill(result: T): Promise<T>;
|
||||
reject(err: any): Promise<T>;
|
||||
resolve(err: any, result: T): Promise<T>;
|
||||
|
||||
onFulfill(listener: (result: T) => void): Promise<T>;
|
||||
onReject(listener: (err: any) => void): Promise<T>;
|
||||
onResolve(listener: (err: any, result: T) => void): Promise<T>;
|
||||
on(event: string, listener: Function): Promise<T>;
|
||||
|
||||
// Deprecated methods.
|
||||
addBack(listener: (err: any, result: T) => void): Promise<T>;
|
||||
addCallback(listener: (result: T) => void): Promise<T>;
|
||||
addErrback(listener: (err: any) => void): Promise<T>;
|
||||
complete(result: T): Promise<T>;
|
||||
error(err: any): Promise<T>;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user