當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mongoose.Connection類代碼示例

本文整理匯總了TypeScript中mongoose.Connection的典型用法代碼示例。如果您正苦於以下問題:TypeScript Connection類的具體用法?TypeScript Connection怎麽用?TypeScript Connection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Connection類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Promise

export const connection = () => new Promise((resolve, reject) => {
  mongoose.connect(`${config.get('DB_HOST')}/${config.get('DB_NAME')}`);
  const db: Connection = mongoose.connection;
  db.on('error', error => {
    logger.error(`Error connecting to database.`);
    reject(error);
  });
  db.once('open', () => {
    logger.info(`Connexion to dabatase successfull.`);
    resolve(mongoose);
  });
});
開發者ID:Cyphle,項目名稱:Portfolio,代碼行數:12,代碼來源:mongo.config.ts

示例2: function

export default function(db: Connection): Model<Document> {
	const schema = new Schema({
		url: { type: String, required: true, unique: true }
	});

	return db.model('VisitHistory', schema, 'visitHistories');
}
開發者ID:syuilo,項目名稱:ssmato.me,代碼行數:7,代碼來源:visit-history.ts

示例3: function

export default function(db: Connection): Model<Document> {
	const schema: any = new Schema({
		createdAt: { type: Date, required: true, default: Date.now },
		bio: { type: String, required: false, default: null },
		gender: { type: String, required: false, default: null },
		image: { type: Buffer, required: false, default: null },
		icon: { type: Buffer, required: false, default: null },
		color: { type: String, required: false, default: '#000000' },
		kana: { type: String, required: true },
		name: { type: String, required: true },
		ruby: { type: String, required: false, default: null },
		screenName: { type: String, required: true },
		aliases: [{ type: String, required: false, default: null }],
		series: [{ type: Schema.Types.ObjectId, required: true, ref: 'Series' }],
		ssCount: { type: Number, required: false, default: 0 }
	});

	if (!schema.options.toObject) {
		schema.options.toObject = {};
	}
	schema.options.toObject.transform = (doc: any, ret: any) => {
		ret.id = doc.id;
		delete ret._id;
		delete ret.__v;
	};

	return db.model('Character', schema, 'characters');
}
開發者ID:syuilo,項目名稱:ssmato.me,代碼行數:28,代碼來源:character.ts

示例4: function

export default function(db: Connection): Model<Document> {
	const schema = new Schema({
		app: { type: Schema.Types.ObjectId, required: false, default: null, ref: 'Application' },
		key: { type: String, required: true, unique: true },
		user: { type: Schema.Types.ObjectId, required: true, ref: 'User' }
	});

	return db.model('UserKey', schema, 'UserKeys');
}
開發者ID:Tosuke,項目名稱:Misskey-API,代碼行數:9,代碼來源:user-key.ts

示例5: function

export default function(db: Connection): Model<Document> {
	const schema = new Schema({
		createdAt: { type: Date, required: true, default: Date.now },
		followee: { type: Schema.Types.ObjectId, required: true, ref: 'User' },
		follower: { type: Schema.Types.ObjectId, required: true, ref: 'User' }
	});

	return db.model('UserFollowing', schema, 'UserFollowings');
}
開發者ID:akionux,項目名稱:Misskey-API,代碼行數:9,代碼來源:user-following.ts

示例6: function

export default function(db: Connection): Model<Document> {
	mongooseAutoIncrement.initialize(db);

	const schema = new Schema({
		createdAt: { type: Date, required: true, default: Date.now },
		cursor: { type: Number },
		followee: { type: Schema.Types.ObjectId, required: true, ref: 'User' },
		follower: { type: Schema.Types.ObjectId, required: true, ref: 'User' }
	});

	// Auto increment
	schema.plugin(mongooseAutoIncrement.plugin, {
		model: 'UserFollowing',
		field: 'cursor'
	});

	return db.model('UserFollowing', schema, 'UserFollowings');
}
開發者ID:Tosuke,項目名稱:Misskey-API,代碼行數:18,代碼來源:user-following.ts

示例7: function

export default function(db: Connection): Model<Document> {
	const schema: any = new Schema({
		createdAt: { type: Date, required: true, default: Date.now },
		image: { type: Buffer, required: false, default: null },
		description: { type: String, required: false, default: null },
		title: { type: String, required: true, unique: true },
		kana: { type: String, required: true },
		aliases: [{ type: String, required: false, default: null }],
		ssCount: { type: Number, required: false, default: 0 }
	});

	if (!schema.options.toObject) {
		schema.options.toObject = {};
	}
	schema.options.toObject.transform = (doc: any, ret: any) => {
		ret.id = doc.id;
		delete ret._id;
		delete ret.__v;
	};

	return db.model('Series', schema, 'series');
}
開發者ID:syuilo,項目名稱:ssmato.me,代碼行數:22,代碼來源:series.ts

示例8: function

var coll2 = new mongoose.Collection('', new mongoose.Connection(null));
coll2.$format(999).toLowerCase();
/* inherited properties */
coll2.initializeOrderedBulkOp;
coll2.indexExists;

/*
 * section connection.js
 * http://mongoosejs.com/docs/api.html#connection-js
 *
 * section section drivers/node-mongodb-native/connection.js
 * http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-connection-js
 */
var conn1: mongoose.Connection = mongoose.createConnection('mongodb://user:pass@localhost:port/database');
conn1 = new mongoose.Connection(mongoose);
conn1.open('mongodb://localhost/test', 'myDb', 27017, {
  replset: null,
  config: {
    autoIndex: false
  }
}, function (err) {}).open('');
conn1.openSet('mongodb://localhost/test', 'db', {
  replset: null,
  mongos: true
}, function (err) {}).then(cb).catch(cb);
conn1.close().catch(function (err) {});
conn1.collection('name').$format(999);
conn1.model('myModel', new mongoose.Schema({}), 'myCol').find();
conn1.modelNames()[0].toLowerCase();
conn1.config.hasOwnProperty('');
開發者ID:RaySingerNZ,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:mongoose-tests.ts

示例9: require

import {Connection, Document, Model} from "mongoose";
import {Constants} from "../config/Constants";
import Database = require("../databases/Database");
import {ICustomerDocument} from "./interfaces/ICustomerDocument";
import CustomerSchema = require("../databases/schemas/CustomerSchema");

let connection: Connection = Database.getConnectin();

// Define and export Mongoose.Model object
const customerModel: Model<Document> = connection.model<ICustomerDocument> ("Customer", CustomerSchema);
export = customerModel;
開發者ID:iammen,項目名稱:crud-typescript-example,代碼行數:11,代碼來源:CustomerModel.ts

示例10: connect

    static connect (): Mongoose {
        if (this._instance) {
            return this._instance;
        }

        // Assign Mongoose connection to static private member
        this._connection = mongoose.connection;
        // Bind events
        this._connection.on("error", () => {
            console.log("Error to connect database.");
        });
        this._connection.once("open", () => {
            console.log("Connected to database success.");
        });

        this._instance = mongoose.connect(Constants.DB_CONNECTION_STRING);
        return this._instance;
    }
開發者ID:iammen,項目名稱:crud-typescript-example,代碼行數:18,代碼來源:Database.ts


注:本文中的mongoose.Connection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。