Tag: mongodb

在mongoose中id和_id有什么区别?

mongoose中的_id和id什么区别? 哪个更适合参考?

如何在Mongoose模型中定义方法?

我的locationsModel文件: mongoose = require 'mongoose' threeTaps = require '../modules/threeTaps' Schema = mongoose.Schema ObjectId = Schema.ObjectId LocationSchema = latitude: String longitude: String locationText: String Location = new Schema LocationSchema Location.methods.testFunc = (callback) -> console.log 'in test' mongoose.model('Location', Location); 要调用它,我正在使用: myLocation.testFunc {locationText: locationText}, (err, results) -> 但是我得到一个错误: TypeError: Object function model() { Model.apply(this, arguments); } has no […]

mongoose填充vs对象嵌套

使用mongoose种群和直接目标包含之间是否有任何性能差异(查询的处理时间)? 什么时候应该使用? mongoose群体例子: var personSchema = Schema({ _id : Number, name : String, stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }] }); var storySchema = Schema({ _creator : { type: Number, ref: 'Person' }, title : String, }); mongoose对象嵌套示例: var personSchema = Schema({ _id : Number, name : String, stories : [storySchema] }); var storySchema […]

我如何使用Node.js在MongoDB中使用cursor.forEach()?

我在我的数据库中有一个巨大的文件集合,我想知道如何运行所有文件并更新它们,每个文件具有不同的值。

MongoDB节点检查objectid是否有效

如何使用Node的驱动程序检查ObjectID是否有效 我试过了 : var BSON = mongo.BSONPure; console.log("Validity: " + BSON.ObjectID.isValid('ddsd')) 但是我总是得到一个exception,而不是真或假。 (例外是只是一个'扔e; / / process.nextTick错误,或'错误'事件首先打勾'

Mongodb与Postgres在Nodejs应用程序

我正在构build一个nodejs应用程序,并完全在nosql mongodb和rmds PostregresSql之间撕裂。 我的项目是创build一个开源示例项目,用于logging访问者,并使用nodejs在网页上实时显示访客统计信息。 我打算首先使用mongodb,因为很多nodejs的例子和教程,albiet大多是较老的,使用它和Paas主机有一个免费的teir是很多的。 然而,我最近在mongodb上看到了很多抨击,发现那些试图使用mongodb的人最终转向了postgres。 http://blog.engineering.kiip.me/post/20988881092/a-year-with-mongodb http://dieswaytoofast.blogspot.com/2012/09/mysql-vs-postgres-vs-mongodb.html http: //www.plotprojects.com/why-we-use-postgresql-and-slick/我也是一个heroku的粉丝,并且听说过很多关于postgress的问题,发现sql查询有时候可以很好。 我不是一个数据库专家,所以我不能告诉我的生活要走哪条路。 如果你能给出一些build议,哪一个可以考虑以及为什么,我真的会赞同它。 我有几个标准: 既然我想这是一个例子,那么有一个方法来容纳大小适中的数据是很好的。 我知道mongodb挑衅地提供这个,但像heroku这样的postgres paas似乎有非常小的数据库(因为我logging每个访问者的网站) 一个简单易懂的数据库。 performance并不重要,但速度不能伤害 感谢所有的帮助! 注意 :请不要火焰大战,大家有自己的看法:)

node.js找不到模块“mongodb”

我正在通过我的第一个node.js项目。 我已经安装了mongodb,有一个server.js文件,当我尝试运行它时,我得到这个错误 module.js:340 throw err; ^ Error: Cannot find module 'mongodb' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:362:17) at require (module.js:378:17) 我很确定我已经安装了mongodb,我是来自C#窗口背景的unix新手,但我认为这是一个没有正确configuration的path?

如何使用mongoosefindOne

我有下面的模式(道歉,它是在咖啡脚本) Schema = mongoose.Schema AuthS = new Schema auth: {type: String, unique: true} nick: String time: Date Auth = mongoose.model 'Auth', AuthS 我只想恢复一个绝对在我的数据库中的logging: Auth.findOne({nick: 'noname'}, function(obj) { console.log(obj); }); 不幸的是这总是logging为null 。 mongo shell中的db.auths.findOne({nick: 'noname'})总是返回一个值。 到底是怎么回事?

错误:getaddrinfo ENOTFOUND在获取调用的nodejs中

我在节点上运行一个Web服务器,代码如下 var restify = require('restify'); var server = restify.createServer(); var quotes = [ { author : 'Audrey Hepburn', text : "Nothing is impossible, the word itself says 'I'm possible'!"}, { author : 'Walt Disney', text : "You may not realize it when it happens, but a kick in the teeth may be the best thing […]

Node.js – 等待多个asynchronous调用

我试图在渲染一个Jade模板之前进行多个MongoDB查询,但是我无法完全弄清楚如何在呈现模板之前等待所有的Mongo查询完成。 exports.init = function(req, res){ var NYLakes = {}; var NJLakes = {}; var filterNY = {"State" : "NY"}; db.collection('lakes').find(filterNY).toArray(function(err, result) { if (err) throw err; NYLakes = result; }); var filterNJ = {"State" : "NJ"}; db.collection('lakes').find(filterNJ).toArray(function(err, result) { if (err) throw err; NJLakes = result; }); res.render('explore/index', { NYlakes: NYLakes, NJlakes: NJLakes } ); […]