Tag: mongodb

Nodejs会话Mainlanience

是否有任何现有的Node.js会话pipe理库? 我正在寻找一些可以为用户进行密码authentication(使用MongoDB作为后端)并维护会话。

Mongo发现一个访问属性的问题

好吧,也许我没有看到它,但这个查询看起来很好: db.bind('links'); db.links.findOne({ short_id: req.params.id }, function(err, link) { console.log(link["post_id"]); // I also tried console.log(link.post_id) res.jsonp(link); }); 但是错误说:“TypeError:无法读取null的属性'post_id'”。 然后我试图删除console.log,我得到了浏览器上的输出,所以链接不是null它有一定的价值,但为什么它是trowing和错误访问它的属性,任何想法?

如何在express / mongoose中创build访问控制

我有expressjs和Mongoose(有mongodb)的项目。 我有多个用户angular色 – pipe理员,经理,用户 我希望每个表的几个字段可以被pipe理员访问,而其他的则不可以。 默认情况下用户不会有任何编辑访问权限,pipe理员将具有完全访问权限。 一种方法是通过查看用户的angular色来在每个控制器function中进行这种控制。 有没有简单的方法来做,如检查用户是否有控制,然后为每个表保存一次,以避免业务逻辑的重复。 我的ordersschema如下。 我不希望没有pipe理员权限的客户信息。 var OrderSchema = new Schema({ order_type: { type: String, trim: true }, customer_phone: { type: String, trim: true } }); var managerAccess = [order_type]; 我的用户模式如下(更多字段没有添加) var UserSchema = new Schema({ firstName: { type: String, trim: true, default: '', validate: [validateLocalStrategyProperty, 'Please fill in your first […]

mongoose填充其他语法

我有两个这样的模型: var UserSchema = mongoose.Schema({ name : {type: String, required: true}, image : {type: String, required: true} }); var RoomSchema = mongoose.Schema({ _user : {type: mongoose.Schema.ObjectId, ref: 'User', required: true}, name : {type: String, required: true} }); 我知道如何使用像这样的填充: Room.findOne({_id : req.body._id}).populate('_user').exec(function(err, room){ console.log(room); }); 工作正常,我的问题是,我需要写一些像( 女巫是错的 ): Room.findOne({_id : req.body._id}, function(err, room){ room.populate('_user'); console.log(room); }); […]

附加在Schemaless Array内

我是MongoDB的新手,到目前为止玩弄它,遇到了一个问题,在这里我试图在Schema-Less数组中添加多个对象时遇到困难。到目前为止,我尝试$ push追加数组内的多个对象,但是,有一个Mongo错误 。 [MongoError: Can't use $push/$pushALL within non-array 我不知道为什么我得到这个错误,当使用$推数组 架构: EventTypeSchema = new Schema(){ type: String, eventID: { type: Schema.Types.ObjectId, ref: 'User' } } PersonSchema = new Schema(){ PersonID: { type: Schema.Types.ObjectId, ref: 'User' } Invitation: [ ] //Schema-less } 在控制器我有访问到EventType和人员模型控制器: exports.update = function(req,res){ var event = new EventType(); event.type = 'EVENT'; event.eventID = […]

MEAN堆栈 – 在前端显示来自MongoDB的信息

我正在尝试构build一个基本的MEAN栈应用程序,并且对于如何在前端显示存储在mongodb中的信息感到非常困惑。 build立数据库查询的过程是什么,然后在视图中显示。 服务器是否应该使数据库请求和angular度显示信息? 在所有的教程中,我一直在研究通过mongodb和angular /前端之间的交互,看起来非常模糊。 目前(正如我正在设置一个网球阶梯应用程序),我只想通过查询数据库中的信息来显示索引页面上的播放列表。 这是正确的方法吗? 对这个模糊的问题抱歉,但我真的很难理解这是如何实现的。 我最近一直在使用Rails作为比较(尽pipe显然是非常不同的),在这种情况下,你可以使用ActiveRecord来查询数据库,并为查询结果定义一个variables,然后在你的视图中使用该variables来显示数据。

客户端生成的JSON存储在MongoDB服务器端,application / json不能正确parsing?

我会简短的; 我有一个客户端表单 ,允许创build“测验”,一系列附有答案的问题发送到服务器存储到MongoDB。 我试图按照W3的规范来做到这一点,但承诺的结果并不符合我得到的结果。 我想我的JSON由嵌套对象组成,如下所示: { "_id": "54a884c68999af900fc28dcb", "name": "testquiz", "author": "user", "questions": [ { "text": "question one", "answers": [ { "text": "answer one", "correct": false }, { "text": "answer two", "correct": true } ] }, { "text": "question two", "answers": [ { "text": "answer one", "correct": true }, { "text": "answer two", "correct": false […]

在查询mongodb之前,我是否应该关心在id中过滤$ nin ID?

所以我有一个node.js代码,它有一个$ in和$ nin id的mongodb。 “$ nin”的列表实际上比“$ in”列表大。 在“我的实现”我做了“简单的方法”,通过将两个ID列表传递给mongodb: query = { _id: { $in: in_list, $nin: not_in_list } } 然后我的同事过来,从“$ in”列表中删除了所有“$ nin”id,只是查询$ in_list = _.difference in_list, not_in_list query = { _id: { $in: in_list } } 我的假设是,mongodb足够聪明,能够比node.js更快地处理这个问题,但是我实际上并不知道这个差异是否是实际可测量的和/或显着的。 任何input?

我可以从testing中连接mongoose吗?

我正在尝试使用mongoose运行连接到mongodb的chaitesting,但是由于“预期未定义为对象”而失败。 我正在使用function相同的方法。 我是否正确连接到数据库? var expect = require('chai').expect; var eeg = require('../eegFunctions'); var chai = require("chai"); var chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); var mongoose = require('mongoose'); var db = mongoose.connection; db.on('error', console.error); db.once('open', function callback(){console.log('db ready');}); mongoose.connect('mongodb://localhost/eegControl'); test("lastShot() should return an object", function(){ var data; eeg.lastShot(function(eegData){ data = eegData; }); return expect(data).to.eventually.be.an('object'); });

METEOR – 是否有处理人口的机制?

Mongoose(和MongoDB)似乎更喜欢dbref /人口习惯而不是传统的SQL关系。 虽然我尊重这里提出的解决scheme的简单性: 如何在Meteor中显示相关的子文档属性 MongoDB文档在这里与DBRefs对话: http ://docs.mongodb.org/manual/reference/database-references/#dbref-explanation 和Mongoose人口logging在这里: http : //mongoosejs.com/docs/populate.html 从一个查询中提取一个项目并将其传递到另一个查询当然是一种select,能够提取一个提供所有所需数据的单个查询的语法糖果具有优势。 什么是meteor哲学呢?