Tag: mongodb

持久login停止使用Node.js,Express,PassportJS,Connect-Mongo

在某些时候,持续login与我的应用程序停止工作,我不知道为什么。 事情是,即使我只是刷新页面,应用程序,用户注销。 我使用MEAN.js提供的脚手架构build了这个应用程序,所以我无法定位问题。 我可以帮忙debugging吗? 任何帮助赞赏。 下面是我的快速安装文件 var fs = require('fs'), http = require('http'), https = require('https'), express = require('express'), morgan = require('morgan'), bodyParser = require('body-parser'), session = require('express-session'), compress = require('compression'), acl = require('acl'), methodOverride = require('method-override'), cookieParser = require('cookie-parser'), helmet = require('helmet'), passport = require('passport'), mongoStore = require('connect-mongo')({ session: session }), flash = require('connect-flash'), […]

如何执行与Mongoose runCommand?

我正在使用Node.js和Mongoose来访问我的MongoDB。 我正在使用存储一些地理坐标的模型。 我有他们索引,一切似乎按预期工作。 我想要做的是从我的请求中获取最近的东西。 在MongoDB控制台上,我做了这样的事情: distances = db.runCommand({ geoNear : "deals", near : [11.252, 14.141], spherical : true, maxDistance : 300 }).results 但是,我不知道如何用Mongoose做到这一点。 这里是关于我试图使用的命令的更多信息: http : //www.mongodb.org/display/DOCS/Geospatial+Indexing 谢谢,何塞

监测MongoDB的“后台操作”?

编辑:基本上我正在寻找一些关于如何理解我的MongoDB实例上运行的后台操作的提示,并可能在必要时减less/禁用它们,以免它们干扰运行testing。 我已经尝试了mongostat和mongotop但没有find任何帮助我了解后台操作正在运行以及正在启动的操作。 在开始运行我的testing之前, db.currentOp()在运行时始终返回一个空数组。 我经常运行testing,同时开发节点(摩卡,黄瓜)。 从昨天开始,大约有25%的服务器初始化尝试连接到mongodb时出现以下错误: **Unhandled rejection MongoError: exception: cannot perform operation: a background operation is currently running for collection** somecollection at Function.MongoError.create (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11) at /somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:793:66 at bound (domain.js:254:14) at runBound (domain.js:267:12) at Callbacks.emit (…/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3) at null.messageHandler (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23) at Socket.<anonymous> (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:294:20) at Socket.emit (events.js:107:17) at readableAddChunk (_stream_readable.js:163:16) at Socket.Readable.push (_stream_readable.js:126:10) at TCP.onread (net.js:538:20) 在运行testing之前,我们使用pow-mongodb-fixtures来清除数据库并填充一些基本数据,这就是发生这种情况的原因。 […]

将嵌套对象保存在mongoose中

我刚接触node.js和MongoDb(以及一般的文档数据库)。 从PHP / MySQL背景来看,我在构build和保存数据方面苦苦挣扎。 我试图创build一个小应用程序,我可以添加多种配料的食谱。 我有一堆预填充的成分作为种子数据,其模式如下所示: var IngredientSchema = new Schema({ name: { type: String, trim: true, required: true, index: { unique: true } }, created: { type: Date, default: Date.now } }); var Ingredient = mongoose.model('Ingredient', IngredientSchema); 配方目前看起来像这样: var RecipeSchema = new Schema({ name: { type: String, trim: true }, ingredients: [ { type: […]

插入数据到MongoDB – 没有错误,没有插入

我目前正在试图使用mongoDB和nodeJSregistry单 – 我已经创build了新的数据库和集合 – 我想在我的数据库中存储:用户名,密码,电子邮件和insert_time。 我已经添加了唯一的索引到用户名/电子邮件,并检查它是否工作 – 我不能添加使用mongo的控制台或rockmongo(php mongodb经理)重复的条目 – 所以它工作正常。 然而,当应该注册一个新账户的代码片段正在被执行并且使用已经在数据库中的数据进行插入时,它将返回一个对象,该对象包含所有应该添加新数据的数据,唯一身份。 重点是 – 它应该返回一个错误,说明条目不能重复,插入失败 – 而是返回数据,并给它一个新的ID。 已经驻留在数据库中的数据保持不变 – 即使ID保持不变 – 它不会被脚本插入返回的新数据重写。 所以,问题是…我做错了什么? 或者,也许一切正常,数据库的插入应该返回数据,即使它失败了… … 我甚至在执行索引之前尝试过定义索引。 我尝试使用mongoDB的默认函数和mongoJS函数来插入数据,结果在两种情况下都是相同的。 我试图执行的代码(对于mongoJS ): var dbconn = require("mongojs").connect('127.0.0.1:27017/db', ['users']); var register = function(everyone, params, callback) { // TODO: validation dbconn.users.ensureIndex({username:1},{unique:true}); dbconn.users.ensureIndex({email:1},{unique:true}); dbconn.users.save( { username: params.username, password: params.password, email: params.email, insert_time: […]

防止Node.js中与数据库相关的争用情况

概观 我正在尝试了解如何在使用Node.js时使用模型实例来确保asynchronous安全。 在这里,我在代码示例中使用了Mongoose ODM,但这个问题适用于任何使用Node.js采用的asynchronous事件驱动的I / O方法的数据库。 考虑下面的代码(它使用Mongoose进行MongoDB查询): 片段A MyModel.findOne( { _id : <id #1> }, function( err, doc ) { MyOtherModel.findOne( { _id : someOtherId }, ( function(err, otherDoc ) { if (doc.field1 === otherDoc.otherField) { doc.field2 = 0; // assign some new value to a field on the model } doc.save( function() { console.log( […]

在amazon EC2上托pipenodeJS / mongoose web应用程序

我想在云端托pipe一个nodeJS / mongoose / mongodb应用程序,由于EC2有一个免费的MicroInstance,所以我的问题是: 有没有一步一步的教程,我怎么能起床和运行nodejs /亚马逊EC2中的mongoose应用程序?

如何用MEAN和sails.js开始一个新的项目

我在过去创build了一个带有node.js,express和angular.js的web应用程序。 我正在开始一个新的项目,我也想使用MongoDB。 那将是MEAN堆栈。 只需使用MEAN就可以开始一个项目: http : //mean.io/ 。 现在,我已经编写了REST API,我听说过sails.js,这听起来非常有吸引力。 它可以为你自动创buildREST API。 所以我的问题是, 我会采取什么步骤来启动一个新的项目与MEAN堆栈和sails.js ? 选项: 我会克隆mean.io堆栈,运行npm install,然后npm install sails.js? 或者,sails.js似乎有自己的想法来做一个目录结构。 那么我会按照他们的说明安装sails.js http://sailsjs.org/#!getStarted然后npm安装Angular和Mongo? (我想我不会需要mongoose,因为sails.js有它自己的ORM,水线)。 我今天实际上会尝试选项2,但是我会很高兴知道哪些步骤对他人有效。 非常感谢你!

NodeJS + Mongo:插入如果不存在,否则 – 更新

我在我的mongodb集合中有一个对象。 它的模式是: { "instruments": ["A", "B", "C"], "_id": { "$oid": "508510cd6461cc5f61000001" } } 我的collections可能有这样的对象,但可能不会。 我需要检查是否存在带有关键“工具”的对象( 请注意,此时我不知道“工具”是什么值,它可能包含任何值或数组 ),如果存在,则执行更新;否则 – 插入一个新的值。 我怎样才能做到这一点? collection.find( { "instruments" : { $exists : true } }, function(err, object){ if (object) { //update } else { //insert } }); 不起作用((

]从NodeJS到mongodb

我有问题使用下面的示例代码从NodeJS连接到MongoDB。 我尝试运行有或没有sudo“mongod”,但nodejs代码仍然无法连接。 我能够使用“mongo”成功连接到数据库。 运行于:MAC OS 10.6.8 var mongoClient = require('mongodb').MongoClient; mongoClient.connect("mongodb://localhost:27017/test", function(error, db) { if(!error){ console.log("We are connected"); } else console.dir(error); }); 运行上面的代码得到以下错误:[错误:无法连接到[localhost:27017]] 也试过mongoose,但类似的错误: var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function callback () { console.log("DB connected"); // yay! }); 输出:连接错误:[错误:无法连接到[localhost:27017]] 这是mongod的日志 mongod –help for help and startup […]