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


TypeScript mongoose.set函數代碼示例

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


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

示例1: Error

(async () => {
	try {
		logger.info(null, '[app] Starting up...');

		// validate settings
		if (!settings.validate()) {
			throw new Error('Settings validation failed.');
		}

		// bootstrap models
		logger.info(null, '[app] Connecting to MongoDB...');
		mongoose.set('useNewUrlParser', true);
		mongoose.set('useFindAndModify', false);
		mongoose.set('useCreateIndex', true);
		if (config.vpdb.dbLogging.writeQueries) {
			mongoose.set('debug', (collection: string, method: string, query: any, doc: any, options: any) => {
				if (!['find', 'findOne', 'findMany', 'createIndex', 'countDocuments', 'count'].includes(method)) {
					logger.debug(null, '[MongoDB]: %s.%s(%s, %s, %s)', collection, method, JSON.stringify(query), JSON.stringify(doc), JSON.stringify(options));
				}
			});
		}
		await mongoose.connect(config.vpdb.db, { useNewUrlParser: true });

		// bootstrap endpoints
		for (const endPoint of endPoints) {
			logger.info(null, '[app] Registering %s:', endPoint.name);
			await server.register(endPoint);
		}

		// global serializers
		state.serializers.Moderation = new ModerationSerializer();

		server.postRegister(endPoints);

		// setup ACLs
		await initAcls();

		// cleanup inactive storage
		logger.info(null, '[app] Cleaning up inactive storage files older than one week.');
		await FileUtil.cleanup(3600000 * 24 * 7);

		// go!
		server.start();

	} catch (err) {
		/* istanbul ignore next */
		logger.error(null, err);
	}
})();
開發者ID:freezy,項目名稱:node-vpdb,代碼行數:49,代碼來源:index.ts

示例2:

      .then((connection) => {
        // Enabling mongoose debug mode if required
        mongoose.set("debug", config.db.debug);

        // Call callback FN
        if (callback) { callback(connection.db); }
      })
開發者ID:relevantmedia,項目名稱:angular2_mean,代碼行數:7,代碼來源:mongoose.ts

示例3: function

 mongoose.connect(config.mongo.uri, config.mongo.options, function (err) {
   // Log Error
   if (err) {
     console.error(chalk.default.bold.red('Could not connect to MongoDB!'));
     observer.error(err);
   } else {
     // Enabling mongoose debug mode if required
     mongoose.set('debug', config.mongo.debug);
     
     observer.next();
     observer.complete();
   }
 });
開發者ID:projectSHAI,項目名稱:expressgular2,代碼行數:13,代碼來源:index.ts

示例4: new

mongoose.createConnection('localhost', 'database', 3000, {
  user: 'larry',
  config: {
    autoIndex: false
  }
}).open('');
mongoose.disconnect(cb).then(cb).fulfill;
mongoose.get('test');
mongoose.model('Actor', new mongoose.Schema({
  name: String
}), 'collectionName', true).find({});
mongoose.model('Actor').find({});
mongoose.modelNames()[0].toLowerCase();
new (new mongoose.Mongoose()).Mongoose().connect('');
mongoose.plugin(cb, {}).connect('');
mongoose.set('test', 'value');
mongoose.set('debug', function(collectionName: any, methodName: any, arg1: any, arg2: any) {});
mongoose.STATES.hasOwnProperty('');
mongoose.connection.on('error', cb);
new mongoose.mongo.MongoError('error').stack;
mongoose.SchemaTypes.String;
mongoose.Types.ObjectId;
mongoose.version.toLowerCase();

/*
 * section querystream.js
 * http://mongoosejs.com/docs/api.html#querystream-js
 */
var querystream: mongoose.QueryStream;
querystream.destroy(new Error());
querystream.pause();
開發者ID:RaySingerNZ,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:mongoose-tests.ts

示例5: require

/// <reference path='../typings/node/node.d.ts' />
/// <reference path='../typings/mongodb/mongodb.d.ts' />
/// <reference path='../typings/express/express.d.ts' />

var mongoose = require('mongoose');

import options = require('./options-handler');
import log = require('./logger');

// Logs to debug every database query
mongoose.set('debug', options['database']['debug']);

var ObjectId = mongoose.Schema.Types.ObjectId;
var Mixed = mongoose.Schema.Types.Mixed;

// Ensures that the entry is a valid object ID
var isObjectId = function(n) {
  if (!n) {
    // Allow null/undefined
    return true;
  }

  if (typeof n.toString === 'function') {
    return mongoose.Types.ObjectId.isValid(n.toString());
  } else {
    return false;
  }
};

// Ensures that the entry is an array of valid object IDs
var isObjectIdArray = function(n) {
開發者ID:MisterTea,項目名稱:TidalWave,代碼行數:31,代碼來源:model.ts

示例6: require

import * as express from 'express';
import * as helmet from 'helmet';
import * as morgan from 'morgan';
import * as mongoose from 'mongoose';
import {json, urlencoded} from 'body-parser';

const config = require('../../tradejs.config');
const app = express();
app.listen(config.server.email.port, () => console.log(`\n Email service started on      : 127.0.0.1:${config.server.email.port}`));

/**
 * mongo
 */
mongoose.set('debug', true);
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
mongoose.connection.once('open', function () {
	console.log('DB connected');
});
mongoose.connect(config.server.email.connectionString);

/**
 * express
 */
app.use(morgan('dev'));
app.use(helmet());
app.use(json());
app.use(urlencoded({extended: false}));
app.use((req, res, next) => {
	res.header('Access-Control-Allow-Origin', '*');
	res.header('Access-Control-Allow-Headers', '_id, Authorization, Origin, X-Requested-With, Content-Type, Accept');
	next();
開發者ID:Chegeek,項目名稱:TradeJS,代碼行數:31,代碼來源:app.ts

示例7: require

// make bluebird default Promise
Promise = require('bluebird'); // eslint-disable-line no-global-assign

// plugin bluebird promise in mongoose
(mongoose as any).Promise = Promise;

// connect to mongo db
mongoose.connect(config.mongo, { server: { socketOptions: { keepAlive: 1 } } });
mongoose.connection.on('error', () => {
  throw new Error(`unable to connect to database`);
});

// print mongoose logs in dev env
if (config.mongooseDebug) {
  mongoose.set('debug', (collectionName, method, query, doc) => {
    debug(`${collectionName}.${method}`, util.inspect(query, false, 20), doc);
  });
}

// module.parent check is required to support mocha watch
// src: https://github.com/mochajs/mocha/issues/1912
if (!module.parent) {
  const port = config.server.port;
  if (config.server.cert && config.server.key) {
    const options = {
      cert: fs.readFileSync(config.server.cert),
      key: fs.readFileSync(config.server.key)
    };

    https.createServer(options, app).listen(port, () => {
      console.info(`server started on port ${port} (${config.env})`);
開發者ID:eastmaels,項目名稱:v2.api.utopian.io,代碼行數:31,代碼來源:index.ts


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