Tag: mean stack

根据链接结果的属性过滤mongodb文档

我正在开发一个使用MEAN堆栈的购物网站。 考虑有一个名为产品,有12个不同的属性,如颜色,大小,品牌等一个mongoose模型。我想添加一个function,用户筛选产品基于他的select属性和相关的价值,如所有的购物网站。 我如何查询和dynamic查找产品,并链接结果,如果用户做出多个select。

直接在前端自动更新mongodb的更改,而不使用Node Socket.io和angularjs进行页面刷新

我的问题是,如果我直接在mongodb中手动添加一条消息,如何在活动的UI客户端页面中自动显示而不需要刷新。 我的代码如下。 我的情况是,当新客户端访问页面时,显示mongo中的现有logging,从而保持连接。 但是,如果我直接在mongo里添加一条logging并加载一个新的客户端,那么只有这个logging会有logging,而其他的logging只会在刷新时才会得到。 app.js(服务器端脚本) mongoose.connect("mongodb://localhost:27017/some"); var mschema=mongoose.Schema({ message: String, time : {type:Date ,default: Date.now} }); io.sockets.on('connection', function (socket) { chatmsg.find({},function(err,docs) { if(err) console.log("errorr"); else socket.emit('old msgs',docs); }) socket.on('message', function(message) { var newmsg=new chatmsg({message : message}); newmsg.save(function(err) { if(err) { console.log("error"); } else io.sockets.emit('new message',message) ; }) }) controller.js(客户端脚本) var socket=io("http://localhost:3200"); $scope.sendemit=function() { console.log("inside function"+$scope.textchat); […]

Azure托pipe的节点应用程序无法find模块“async / each”

现在我已经将应用程序部署到Azure几个星期了。 但是现在,我已经将数据库集成到后端,它将在日志stream中看到这个错误并给浏览器一个500码的代码。 Application has thrown an uncaught exception and is terminated: Error: Cannot find module 'async/each' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (D:\home\site\wwwroot\node_modules\mongoose\lib\schema.js:11:12) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) mongoose似乎是问题,所以当我排除它时,一切都很好。 我试着在我的package.json中包含async-each作为一个依赖项,但是这没有帮助(我之前没有看到一个带有/ in的模块,所以在这里猜测) 同样在绝望的时刻,我尝试将同一个应用程序推送到另一个Web App服务,但是甚至无法部署。 WebApiClient超时 […]

MongoError:拓扑被破坏(find文档时),实例池被破坏(插入文档时)

我正在尝试使用Node.js,Express和Mongodb来构buildREST API。 我正在使用mongodb npm包来连接数据库,下面是我的sever.js文件代码 var express = require("express"); var app = express(); var bodyParser = require("body-parser"); var port = process.env.PORT || 8080; var mongo = require("mongodb"); var Server = mongo.Server; var Db = mongo.Db; var ObjectID = mongo.ObjectID; try{ var config = require('./configure.js'); }catch(e){ console.log("configuration file is hidden on github for security"); config = null; […]

如何更新mongoose的logging

我正在尝试更新循环中的logging字段,并注意该字段是一个数组,我的代码如下, Employeehierarchy = mongoose.model('Employeehierarchy'), function (done) { var ObjectId = require('mongoose').Types.ObjectId; var item = {'childrens':{$in:[ ObjectId(employee.manager)]}}; Employeehierarchy.find(item).exec(function (err, employeehierarchy) { if (err) { return res.status(400).send({ message: errorHandler.getErrorMessage(err) }); } else { if (employeehierarchy && employeehierarchy.length > 0) { employeehierarchy.forEach(function (v1, i1) { v1.parents = employee._id; employeehierarchy = _.extend(employeehierarchy, v1); employeehierarchy.save(function (err) { }); }); done(); […]

如何将值推送到节点js中的一个对象数组

"default_tabs" : [ { "value" : "Ice" }, { "value" : "Gold" } ] 我想将这个值分配到另一个数组中,使其看起来像下面的样子 selected_values : [{"values" : { "Ice" : "Edit","Gold" : "Edit" },"role" : "Admin"}] 为此我准备下面, default_tabs.forEach(function(i,v){ selected_values.push('values':v) }) 我知道我错了谁能帮助我please.Thanks。

Mean.js不工作。 无法连接到MongoDB

情况: 我下载了这个版本库: https : //github.com/meanjs/mean 遵循并执行所有的指示。 没有$ npm start ,得到以下错误: 错误: Could not connect to MongoDB! { MongoError: failed to connect to server [localhost:27017] on first connect PS:我确实安装了Mongodb,并检查它是否与$ mongod一起工作。 编辑: 完整的错误消息,如果我做$ npm start : + Important warning: config.domain is empty. It should be set to the fully qualified domain of the app. Could not connect […]

在平均申请中的租赁

我正在尝试在MEAN中创build一个多租户应用程序,根据某些variables的值,它应该select一个mongoDB连接forms的连接池,并对集合执行CURD操作。 var mongoose = require('mongoose'); var connectionPool = {}; connectionPool['dbName1'] = mongoose.createConnection('mongodb://localhost/database1'); connectionPool['dbName2'] = mongoose.createConnection('mongodb://localhost/database2'); connectionPool['dbName3'] = mongoose.createConnection('mongodb://localhost/database3'); 连接对象在使用CURD操作时无法正常工作。 错误 – db.collection(…)。find(…).exe不是函数 谢谢。

hasOwnProperty不能在Mongoose中预先validation

我有一个架构 – var PostSchema = new mongoose.Schema({ title: String, link: String, author: {type:String,required:true}, upvotes: {type: Number, default: 0}, comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }] }); PostSchema.pre('validate',function(next){ console.log("Pre validate document printing – "); console.log(this); console.log("Pre validate called. Title : ",this._id); console.log("Author is : ",this.author); console.log("hasOwnProperty : ",this.hasOwnProperty("author")); console.log("this.author==\'\' : ",this.author==''); if(!(this.hasOwnProperty("author"))||this.author==''){ console.log("Here"); this.author="Hacked"; } next(); […]

静态模式方法:不能读取未定义的属性'myFindOrCreate'

为了在我的mongoose-Schemas上运行,我喜欢创build静态方法,但是我不得不承认,这是我第一次尝试使MEAN栈后端启动并运行。 前端和快速路由工作正常,所以我们首先集中在架构 : // tracking.model.ts import mongoose from 'mongoose'; var Schema = mongoose.Schema; var TrackingModuleSchema = new Schema ({ // internal _id modulename : { type: String, required:true,unique:true }, }); TrackingModuleSchema.statics.myFindByName= function (name,cb) { return this.findOne( {name:new RegExp(name,'i')},cb); }; TrackingModuleSchema.statics.myFindOrCreate = function (name,cb) { this.myFindByName(name,function(err,modules) { console.error(err); console.log(modules); cb(err,modules); // TODO return module._id…. }); }; […]