Tag: mongoose

在Passport-Mongoose-Local中使用Mongoose-Role

我试图添加一个用户在Passport-Mongoose-Local .register方法上的一个angular色,当我单击表单来触发该路由上的post时,它只是无限挂起,直到它丢弃连接。 我不知道为什么,但可能是因为在同一架构中使用2个不同的插件? server.js: `//package main dependencies const express = require('express'); const app = express(); const bodyParser = require('body-parser'); const passport = require('passport'), LocalStrategy = require('passport-local').Strategy; const flash = require('connect-flash'); const expressValidator = require('express-validator'); const mongoose = require('mongoose'); //dev dependencies let logger = require('morgan'); //setting view engine for ejs app.set('view engine', 'ejs' ); //middleware app.use(require('express-session')({ […]

MongoDB集合上的Mongoose模型不提取数据

我正在使用MongoDB 3.4.7版本,Mongoose 4.11.13驱动程序在MongoDB集合上创build模型,并创buildAggregationCursor来单独处理每个文档以填充一些JSvariables。 但似乎Mongoose模型没有将任何数据从MongoDB集合中带入游标。 我以前用mongodb驱动尝试过集合操作,但是不起作用(在这里检查) ,而是select了mongoose 。 但是这里似乎还有一些问题,或者我在这里丢失了什么? 为了更好的理解,更新了我的AggregationCursor。 任何快速的帮助将不胜感激。 节点版本3.10.10,ExpressJS 3.2.6 我的Node.JS代码如下: app.get('/reviews',function(req,res) { res.render("chart"); var obj = {}; var mongoose = require('mongoose'); var assert = require('assert'); var schema = new mongoose.Schema({ seller_id: String, product_id: String, product_desc: String, reviews: { total_review_count: Number, five_star_count: Number, four_star_count: Number, three_star_count: Number, two_star_count: Number, one_star_count: Number } }); […]

在Mongoose(MongoDB,Node.JS,express)中的对象中创build对象后复制对象

我创build了一个循环来向不同地区添加产品(包含数据)。 首先,我想将所有产品添加到所有地区。 然后,我将(在不同的操作)从这些地区删除产品。 该网站的前提是,对象将能够被一个地区的用户保留,这将使该对象在该地区不可用,但在其他地区仍然可用。 我在注册时保存用户区域,只允许他们查看其区域中可用的对象。 我创build了名为Regions的对象,并将每个产品添加到区域内的数组。 我将它们存储在区域内的原因是未来我期待数以百计的不同产品,并且相信只要返回区域数组中的所有项目在服务器上比在每个产品中单独检查一个数值容易得多。 我的问题是 当运行我的代码,我得到我的网页内的每个对象的重复。 我使用的代码是: dummyregions.forEach(function(seed){ Region.create(seed, function(err, region){ if(err){ console.log(err); } else { dummyproducts.forEach(function(seedprod){ Product.create(seedprod, function(err, product){ if(err){ console.log(err); } else { region.products.push(product); region.save(); } }); }); } }) }); dummyRegions是一个对象,包含名称“string”和数组= [] dummyproducts包含名称“string”,类别“string”和缩略图图片url“string” 我只有4个虚拟产品和3个地区的testing项目,但这是我得到的结果: 每个地区的重复项目 任何帮助将非常感激!

在mongodb中显示字段值部分匹配的文档

以下是我的电影架构: "_id" : ObjectId("59b9501600fcb397d6acd5bb"), "theatreid" : 2, "name" : "carnival cinemas", "location" : "kanjulmarg", "address" : "sec 2,kanjul, Mumbai, Maharashtra 400703", "shows" : [ { "mname" : "bareily ki barfi", "timings" : [ 10, 13, 14, 16, 22 ] }, { "mname" : "Toilet:ek prem katha", "timings" : [ 8, 9, 14, 16, 20, 23 […]

将mongoose文档转换为其他类似的模型

所以我有我的应用程序的以下布局: UserSchema(包含用户名和密码) var UserSchema = new mongoose.Schema({ firstName: String, lastName: String, email: String, username: String, password: String }, options); UserSchema.plugin(passportLocalMongoose); module.exports = mongoose.model("User", UserSchema); StudentSchema(鉴别者()在用户)与额外的领域 var StudentSchema = new mongoose.Schema({ indexNumber: String, courses: [{ id: { type: mongoose.Schema.Types.ObjectId, ref: "Course" }, entryDate: { type: Date, default: Date.now } }] }, options); module.exports = User.discriminator("Student", StudentSchema); […]

.aggregate()2藏品mongoose

这是第一个模式: const ProSchema = new Schema({ _id: { type: Schema.Types.ObjectId }, Cv: {Fonction: {Pro: {type: Boolean,}, Secretaire: {type: Boolean} } }) 这是第二个Schema: const CabSchema = new Schema({ Pro: [{ type: Schema.Types.ObjectId, ref: 'ProSchema' }], InfoCab: { Nom: {type: String} }); 创build一个内阁: var cabinet = new cabModel({ _id: new mongoose.Types.ObjectId(), InfoCab:{Nom: "Clinique Toto"} //This is the […]

mongoose全文检索不起作用

我正在尝试search一个使用文本作为参数的对象。 我在我的mongodb中有以下数据: [ { "_id": "59d518859eacefa4555d6edb", "id": "A07", "nome": "Outras doenças intestinais por protozoários" }, { "_id": "59d518859eacefa4555d6edc", "id": "A08", "nome": "Infecções intestinais virais, outras e as não especificadas" } ] 我的模特: var cid = new Schema({ id: String, nome: String }, {collection: 'cid'}); cid.index({'id': 'text', 'nome': 'text'}); search方法: var cid = require('./cid.model'); cid.find({$text: {$search: […]

为mongoosevalidation设置错误代码

我正在使用mongoosevalidation来validation我的模型。 例如: var some_schema = new Schema({ title: { type : [String, 'title must be string'], required: [true, 'title is required'] } }) 此架构具有自定义错误消息,我也想设置自定义错误代码

geoNear没有返回任何结果,尽pipe项目在范围内(mongoose)

所以这里是我的模型: const mongoose = require('mongoose'); const Schema = mongoose.Schema; // create geolocation Schema const GeoSchema = new Schema({ type: { type: String, default: "point" }, coordinates: { type: [Number], index: "2dsphere" } }); // create ninja Schema & model const NinjaSchema = new Schema({ name: { type: String, required: [true, 'Name field is required'] }, […]

如何在A-001,A-002等节点或mongoose中生成唯一的序列号

如何使用nodejs和nodejs生成像A-001 , A-002这样A-001唯一ID? 我已经看到mongoose-auto-increament ,但是我需要根据angular色生成id。 例如,如果angular色是客户端,他们的ID应该是C-001如果angular色是用户,则它应该是U-001 。 Sequential ID在节点包里有这个function,但是它的下载量less,所以还有其他的方法可以生成 任何一个给我一些想法?