Tag: mongoose plugins

护照mongoose对象#<架构>没有方法“身份validation”,但我可以看到的方法

我遇到了一个没有道理的问题,无法弄清楚希望有人能够提供帮助。 我正在使用几个mongoose插件,现在正试图整合护照。 我已经添加了如下所示的passport-local-mongoose插件,但是我收到了该方法不存在的错误。 将模式logging到控制台时,我可以看到列出的方法,所以我不确定它为什么不存在。 代码示例: var mongoose = require('mongoose'); var timestamps = require('mongoose-timestamp'); var autoIncrement = require('mongoose-auto-increment'); var passport = require('passport'); var passportLocalMongoose = require('passport-local-mongoose'); var BasicStrategy = require('passport-http').BasicStrategy; var usersSchema = new mongoose.Schema({ firstName: String, lastName: String, email: String, organizationId: Number, description: String }); module.exports = function(app,db){ //mongoose setup options usersSchema.plugin(timestamps); usersSchema.plugin(autoIncrement.plugin, { model: […]

mongoosesearch产生神秘的错误

我正在使用Mongoose-Text-Search插件( https://github.com/aheckmann/mongoose-text-search )来search我的mongodb数据库,但是我收到了一个令我困惑的错误消息,我从未见过之前。 error: name=MongoError, ok=0, errmsg=error processing query: ns=testdb.data limit=100 skip=0 Tree: TEXT : query=test, language=, tag=NULL Sort: { $s: { $meta: "textScore" } } Proj: { $s: { $meta: "textScore" } } planner returned error: failed to use text index to satisfy $text query (if text index is compound, are equality predicates given […]

调用静态方法到Mongoose中的插件中的模式

我写了一个插件做: module.exports = function (schema, options) { schema.statics.customFunction = function (criteria) { // Code }; }; 这是我的模式: 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 如果我在插件之外编写我的静态方法,它正在工作。 这是来自mongoose的限制吗?

mongoose-attachments-aws2js上传目录

我有一个附件架构: var mongoose = require('mongoose'); var s3 = require('./config/secrets').s3; var provider = require('mongoose-attachments-aws2js'); var attachments = require('mongoose-attachments'); attachments.registerStorageProvider('aws2js', provider); var attachmentSchema = new mongoose.Schema({ name: String, date_created: {type: Date, default: new Date()}, is_active: {type: Boolean, default: true} }); attachmentSchema.plugin(attachments, { directory: 'HowToChangeThis', storage : { providerName: 'aws2js', options: { key: s3.key, secret: s3.secret, bucket: s3.bucket, […]

mongoosepaginate由参考文件sorting

我想用“mongoosepaginate”和“NodeJS”以“ departure_country的name对我的Group Model进行sorting。 我的组架构 : var GroupSchema = new Schema({ name: String, flight_date: Date, …. departure_country: {type: Schema.ObjectId, ref: 'Country'}, …. }); 国家图式 : var CountrySchema = new Schema({ name: String, code: String, }); 用这个国家的_ids来selectmongoose般的分类,我不知道如何用name来分类。

Mongoose高级自定义模式对象types

在Mongoose> = 4.4中,找不到涉及自定义对象(或值对象 )的高级 自定义模式types的任何示例。 想象一下,我想要使用一个自定义types,如: function Polygon(c) { this.bounds = [ /* some data */ ]; this.npoints = /* … */ /* … initialize polygon … */ }; Polygon.prototype.area = function surfaceArea() { /**/ }; Polygon.prototype.toObject = function toObject() { return this.bounds; }; 接下来,我实现了一个自定义的SchemaType,如: function PolygonType(key, options) { mongoose.SchemaType.call(this, key, options, 'PolygonType'); } PolygonType.prototype […]

错误:未启用文本search: – 在mongodb中

我得到以下错误: [Error: text search not enabled] 我正在运行下面的函数,它本质上是一个mongoose-mongodb操作。 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) […]

你如何从mongoose中删除模型?

我不是指删除文件或文件。 我的意思是完全删除模型,使mongoose不再知道它。 声明一个模型后,我不知道如何使mongoose忘记该模型,以便它可以被重新创build。 mongoose.model('Book', bookSchema); mongoose.model('Book', bookSchema); 目前上面抛出一个exception。 OverwriteModelError:编译后无法覆盖“Book”模型。 我想能够做到这样的事情… mongoose.model('Book', bookSchema); mongoose.removeModel('Book'); mongoose.model('Book', bookSchema); …并没有得到任何错误。 有任何想法吗?