mongoose-plugins

Retrieve Mongoose Query Queue Time Metrics

久未见 提交于 2021-02-11 13:30:10
问题 In order to optimize the connection pool size, I thought it would make sense to graph query queue times. Is it possible to retrieve this metric from Mongoose? 回答1: See here for node monitoring. You need cmap events that apparently aren't documented there, see Ruby docs for example but they should be published by the node driver also. Track ConnectionCheckOutStarted and ConnectionCheckOutSucceeded and subtract the times to get the wait time. 来源: https://stackoverflow.com/questions/63652084

Retrieve Mongoose Query Queue Time Metrics

限于喜欢 提交于 2021-02-11 13:29:05
问题 In order to optimize the connection pool size, I thought it would make sense to graph query queue times. Is it possible to retrieve this metric from Mongoose? 回答1: See here for node monitoring. You need cmap events that apparently aren't documented there, see Ruby docs for example but they should be published by the node driver also. Track ConnectionCheckOutStarted and ConnectionCheckOutSucceeded and subtract the times to get the wait time. 来源: https://stackoverflow.com/questions/63652084

nested ref to populate mongoose 5.0 nodejs

戏子无情 提交于 2020-02-06 08:24:27
问题 I have two models. The first one is UserSchema and the second one is CategorySchema var UserSchema = Schema({ firstName: { type: String, required: true }, secondName: String, lastName: { type: String, required: true }, email: { type: String, unique: true, required: true }, password: { type: String, required: true }, status: { type: String, required: true }, roles: [{ type: Schema.ObjectId, ref: 'Role' }], publications: [{ title: { type: String, }, description: String, status: { type: String,

Error: text search not enabled:- in mongodb

荒凉一梦 提交于 2020-01-02 03:45:32
问题 I get the following error :- [Error: text search not enabled] I am running the folliowing function which is essentially a mongoose-mongodb operation. var textSearch = require('mongoose-text-search'); exports.dbTextSearch = function () { console.log('dbTextSearch'); var gameSchema = mongoose.Schema({ name: String , tags: [String] , likes: Number , created: Date }); gameSchema.plugin(textSearch); gameSchema.index({ tags: 'text' }); var Game = mongoose.model('Game', gameSchema); Game.create({

populate embed array mongoose 5.0. Nested ref

旧城冷巷雨未停 提交于 2019-12-25 04:00:31
问题 This is the first model. It's located in the folder called models/user.js 'use strict' var mongoose = require('mongoose'); var Schema = mongoose.Schema; var UserSchema = Schema({ publications: [{ description: String, categories: [{ type: Schema.Types.ObjectId, ref: 'Category.subcategories' }] }] The model category. It's located in the folder called models/category.js 'use strict' var mongoose = require('mongoose'); var Schema = mongoose.Schema; var CategorySchema = Schema({ name: String,

populate nested array of nested ref

浪子不回头ぞ 提交于 2019-12-20 06:29:14
问题 The structure of the project is structure The main file is index.js that is located in the main directory. This one has 'use strict' var mongoose = require('mongoose'); var app = require('./app'); var port = process.env.port || 3000; mongoose.connect('mongodb://localhost:27017/changeProducts',(err,res) =>{ if(err){ throw err; }else{ console.log("Base de datos funcionando correctamente.."); app.listen(port, function(){ console.log('Servidor nodejs corriendo(app.listen)... '); }); } }); The

Incorrect document revision number found in post update middleware

自闭症网瘾萝莉.ら 提交于 2019-12-12 04:05:49
问题 I have a Mongoose plugin which I use to increment the documents revision number ( __v ), as well as create revision itself. The plugin covers the Documents Doc.save() middleware function, as well as the Query update and findOneAndUpdate middleware functions. module.exports = ( schema, options ) => { _.forEach( [ 'save','update', 'findOneAndUpdate' ], query => { // Since the Doc.save() middleware is the only document update middleware function, just isolate that one if( query === 'save' )

Adding field in Mongoose plugin gives “TypeError: Invalid value for schema path `CreatedBy.type`”

*爱你&永不变心* 提交于 2019-12-11 11:14:38
问题 I'm trying to make a CreatedBy Mongoose plugin, but when trying to use the ObjectId as the field type it gives me ( "account" is another defined collection already): TypeError: Invalid value for schema path `CreatedBy.type` & here is the plugin code: mongoose = require 'mongoose' module.exports = exports = updatedByPlugin = (schema, options) -> schema.add CreatedBy: type: mongoose.Schema.Types.ObjectId ref: "account" schema.pre "save", (next) -> @CreatedBy = options.accountId next() return

Call to a static method to a schema inside a plugin in Mongoose

不羁岁月 提交于 2019-12-11 02:03:26
问题 I write a plugin that do : module.exports = function (schema, options) { schema.statics.customFunction = function (criteria) { // Code }; }; And here is my Schema : var customPlugin = require('./plugin'); var customSchema = new mongoose.Schema({ // Schema }); customSchema.plugin(customPlugin, {}); var model = mongoose.model('Custom', customSchema); model.customFunction() // I have a undefined here If I write my static method outside of the plugin, it is working. Is it a restriction from

Error: text search not enabled:- in mongodb

不想你离开。 提交于 2019-12-05 09:25:26
I get the following error :- [Error: text search not enabled] I am running the folliowing function which is essentially a mongoose-mongodb operation. var textSearch = require('mongoose-text-search'); exports.dbTextSearch = function () { console.log('dbTextSearch'); var gameSchema = mongoose.Schema({ name: String , tags: [String] , likes: Number , created: Date }); gameSchema.plugin(textSearch); gameSchema.index({ tags: 'text' }); var Game = mongoose.model('Game', gameSchema); Game.create({ name: 'Super Mario 64', tags: ['nintendo', 'mario', '3d'] }, function (err) { Game.textSearch('3d',