How to use mongoose-auto-increment - 10 common examples

To help you get started, we’ve selected a few mongoose-auto-increment examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github surmon-china / nodepress / src / todos / np-mongodb.js View on Github external
useNewUrlParser: true,
    promiseLibrary: global.Promise
  })

  // 连接错误
  mongoose.connection.on('error', error => {
    console.warn('数据库连接失败!', error)
  })

  // 连接成功
  mongoose.connection.once('open', () => {
    console.ready('数据库连接成功!')
  })

  // 自增 ID 初始化
  autoIncrement.initialize(mongoose.connection)
  
  // 返回实例
  return mongoose
}
github i5ting / wechat-dev-with-nodejs / vip-lession-code / app / models / user.js View on Github external
var LOCK_TIME, MAX_LOGIN_ATTEMPTS, SALT_WORK_FACTOR, Schema, UserSchema, bcrypt, mongoose;

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Promise = require('bluebird');
var autoIncrement = require('mongoose-auto-increment');

autoIncrement.initialize(mongoose.connection);

Schema = mongoose.Schema;

SALT_WORK_FACTOR = 10;

MAX_LOGIN_ATTEMPTS = 5;

LOCK_TIME = 2 * 60 * 60 * 1000;

UserSchema = new Schema({
  username: {// 真实姓名
    type: String
  },
  password       : String,
  unionid       : String,
  openid: {// from weixin openid
github surmon-china / nodepress / src / transforms / mongoose.transform.ts View on Github external
* @file Mongoose 模块转换器
 * @module transform/mongoose
 * @author Surmon 
 */

import * as _mongoose from 'mongoose';
import * as _mongoosePaginate from 'mongoose-paginate';
import * as _mongooseAutoIncrement from 'mongoose-auto-increment';
import * as APP_CONFIG from '@app/app.config';

// 各种 Hack
_mongoose.set('useFindAndModify', false);
(_mongoose as any).Promise = global.Promise;

// 初始化翻页插件
_mongooseAutoIncrement.initialize(_mongoose.connection);

// 插件配置初始化
(_mongoosePaginate as any).paginate.options = {
  limit: APP_CONFIG.APP.LIMIT,
};

export const mongoose = _mongoose;
export const mongoosePaginate = _mongoosePaginate;
export const mongooseAutoIncrement = _mongooseAutoIncrement;
export default mongoose;
github surmon-china / nodepress / np-model / page.model.js View on Github external
const mongoose = require('mongoose')
const autoIncrement = require('mongoose-auto-increment')
autoIncrement.initialize(mongoose.connection)

// 页面集合模型
let pageSchema = new mongoose.Schema({

  // 页面名称
  name:  String,

  // 别名
  slug: String,

  // 页面描述
  description: String,

  // 页面内容
  content: { type: String, required: true },
github team-blockon / blockon / blockon-backend / models / agent.js View on Github external
const Agent = new Schema({
  name: [String],
  address: String
});

Agent.statics.create = function(splitName, address) {
  const rating = new this({
    name: splitName, // 자동완성을 위해 자모음을 분리하여 저장한다.
    address: address
  });

  return rating.save();
};

autoIncrement.initialize(mongoose.connection);
Agent.plugin(autoIncrement.plugin,'Agent');


module.exports = mongoose.model('Agent', Agent);
github mooyoul / telegrambot-mailgram / server.js View on Github external
const db      = mongoose.connect(process.env.MONGO_URL, { options: { db: { safe: true } } }, (e) => {
  if (e) throw e;

  log('Connected to mongodb.');

  mongoose.set('debug', process.env.NODE_ENV === "development");
  autoIncrement.initialize(db);

  // Bootstrap models
  requireDir('./models');
  log('Bootstrapped models.');

  const
    bot = new TelegramBot(env.TELEGRAM_BOT_TOKEN, {
      webHook: env.NODE_ENV === 'production' ? {
        port: env.PORT
      } : false,
      polling: env.NODE_ENV === 'development'
    });

  if (env.NODE_ENV === 'production') {
    bot.setWebHook(env.TELEGRAM_WEBHOOK_URL);
  }
github mooyoul / telegrambot-readerman / server.js View on Github external
const db      = mongoose.connect(process.env.MONGO_URL, { options: { db: { safe: true } } }, (e) => {
  if (e) throw e;

  log('Connected to mongodb.');

  mongoose.set('debug', process.env.NODE_ENV === "development");
  autoIncrement.initialize(db);

  // Bootstrap models
  requireDir('./models');
  log('Bootstrapped models.');

  const
    bot = new TelegramBot(env.TELEGRAM_BOT_TOKEN, {
      webHook: env.NODE_ENV === 'production' ? {
        port: env.PORT
      } : false,
      polling: env.NODE_ENV === 'development'
    });

  if (env.NODE_ENV === 'production') {
    bot.setWebHook(env.TELEGRAM_WEBHOOK_URL);
  }
github mooyoul / telegrambot-readerman / sync.js View on Github external
const db      = mongoose.connect(process.env.MONGO_URL, { options: { db: { safe: true } } }, (e) => {
  if (e) throw e;

  log('Connected to mongodb.');

  mongoose.set('debug', process.env.NODE_ENV === "development");
  autoIncrement.initialize(db);

  // Bootstrap models
  requireDir('./models');
  log('Bootstrapped models.');

  // Create push-only bot
  const
    bot = new TelegramBot(env.TELEGRAM_BOT_TOKEN, {
      webHook: false,
      polling: false
    });

  log('Created bot. Starting sync...');

  // Register execution timeout
  setTimeout(() => {
github Inkrato / inkrato / models / User.js View on Github external
// If they only have an email, use that with Gravatar
  if (this.email) {
    var md5 = crypto.createHash('md5').update(this.email).digest('hex');
    return 'https://gravatar.com/avatar/' + md5 + '?s=' + size + '&d=retro';
  }
  
  // Fallback: If they don't have an email, use their User ID with Gravatar
  var md5 = crypto.createHash('md5').update(this._id+'@user.inkrato.com').digest('hex');
  return 'https://gravatar.com/avatar/' + md5 + '?s=' + size + '&d=retro';
};

/**
 * Auto-incrimenting ID value (in addition to _id property)
  */
var connection = mongoose.createConnection(config.secrets.db);
mongooseAutoIncrement.initialize(connection);
schema.plugin(mongooseAutoIncrement.plugin, {
    model: 'User',
    field: 'userId',
    startAt: 1
});

module.exports = mongoose.model('User', schema);
github chevtek / mongoose-simpledb / index.js View on Github external
db.connection.once('open', function () {
            // If mongoose-auto-increment plugin is installedInitialize mongoose-auto-increment plugin.
            if (settings.autoIncrementNumberIds)
                autoIncrement.initialize(db.connection);

            // Find and load all Mongoose dbmodels from the dbmodels directory.
            fs.readdir(settings.modelsDir, function (err, files) {
                if (err) return settings.callback(err);
                for (var i in files) {
                   var file = files[i];
                    if (path.extname(file) === '.js' || path.extname(file) === '.coffee') {
                        var modelName = path.basename(file.replace(path.extname(file), '')),
                            modelData = require(path.join(settings.modelsDir, file));

                        if (!modelData.hasOwnProperty('schema'))
                            return settings.callback(new Error('Model file ' + file + ' is invalid: No schema.'));

                        // Create schema based on template in model file.
                        var schema;
                        if (modelData.schemaOptions)

mongoose-auto-increment

This plugin allows you to auto-increment any field on any mongoose schema that you wish.

MIT
Latest version published 9 years ago

Package Health Score

53 / 100
Full package analysis

Popular mongoose-auto-increment functions