Tag: mongodb

使用Aleph / Laminaasynchronous访问MongoDB

我一直在阅读Clojure一段时间,我正在考虑它作为Node.js(我已经用于另一个项目)的替代品。 最有希望的图书馆似乎是Aleph / Lamina,遗憾的是没有像Node那么多的例子。 我的问题是: 我如何处理asynchronous操作链的请求,如从MongoDB读取文档,做一些计算,保存新文档并将其发送到响应中? 我无法从Lamina wiki页面中的示例中编写它。 这听起来像一个相当常见的用例,我很惊讶没有发现任何代码显示它。 如果你能给我看一些示例代码,那将是非常好的。 这种设置是否适合于重负载的服务器(比如每秒几万个请求)? 我无法为每个新请求创build一个线程,所以我需要类似于Node方法的东西。 有没有使用这种方法的中型或大型公司的例子? 有没有更好的Clojure替代节点(除了Aleph / Lamina)? 也许Clojurescript目标节点? 我的客户端不是用Javascript编写的,所以在客户端和服务器端使用相同的语言在我的情况下不是一个优势。 谢谢!

mongoose:一系列的自定义实例

根据文件我可以做这样的事情: var animalSchema = new Schema({ name: String, type: String }); animalSchema.methods.findSimilarTypes = function (cb) { return this.model('Animal').find({ type: this.type }, cb); } 假设我有另一个function: animalSchema.methods.owner ,如果animalScheme.owner是xyz,那么它将过滤search查询{…, owner: xyz} 有没有可能顺序使用实例? 我怎样才能做到这一点? var animalSchema.findSimilarTypes().owner("xyz") ? 任何提示?

在Mongoose中,如何在具有.create(),.id()和.remove()function的模型中创buildMongooseArray / Collection

我的模式: Account: mongoose.model('Account', new Schema({ account_name: String, company: String, notes: String, contact_info: [this.ContactInfo] })), ContactInfo: mongoose.model('ContactInfo', new Schema({ name: String, email: String, phone: String, notes: String })) 当我尝试对contact_info做任何操作时,它说方法不存在。 var c = new ContactInfo…); var a = new Account(…); a.contact_info.create(c); //error, create doesn't exsit a.contact_info.push(c); //works a.contact_info.id(…).remove(); //id doesn't exist 难道我做错了什么? 我的完整代码在这里(不是太多): https : //github.com/nycitt/node-survey-builder-api-server/blob/master/accounts.js 顺便说一下,我从Backbone.js接收input

backbone.js和express:遇到一个查询string按字段search一个mongodb集合的麻烦

我是新来的骨干,快递和mongodb。 我想传递一个查询string按字段searchMongoDB集合。 我做错了什么。 如果我从路由器注释掉“获取”,则find页面。 如果我尝试获取,那么我得到一个页面未find错误。 我试图隔离它的中断,但骨干架构仍然让我感到困惑。 提前致谢。 (我打赌这是在我的mongodb调用语法问题)克里斯汀 这是我的代码。 这个URL应该返回“type”= 3的集合。 localhost:8888/#content/3 型号/ models.js: window.Content = Backbone.Model.extend({ urlRoot: "/content", idAttribute: "_id" }); window.ContentCollection = Backbone.Collection.extend({ model: Content, url: "/content" }); 意见/ content.js window.ContentListView = Backbone.View.extend({ initialize: function () { this.render(); }, render: function () { //return this; this.$el.append('<ul class="thumbnails">'); this.collection.each(function(model) { this.$('.thumbnails').append(new ContentView({model: model}).render().el); }, […]

我怎样才能在mongodb的输出查询上添加条件字段?

我的模式如下所示: var productSchema = new Schema({ name : String, likes : [{ user_id : Schema.Types.ObjectId, date : Date }] }); 假设我有这个集合 { name : A, likes : [ {user_id : id1, date : blahblah}, {user_id : id2, date : balh}] } { name : B, likes : [ {user_id : id1, date : blahblah}] } […]

node.js只传递给mongodb值

我在node.js和mongodb上开发一个项目,并表示必须处理事务。 我可以硬编码的variables要放到MongoDB,但如果不是所有的字段被填写(不是所有的都是必需的),那么我只是把空数据到数据库中。 这段代码的作品: var d = new Date(); var n = d.toJSON(); var date = n; var address = req.body.property_address; var client_name = req.body.client_name; var sales_price = req.body.sales_price; var commission_percent = req.body.commission_percent; var referral = req.body.referral; var donation = req.body.donation; var client_source = req.body.client_source; var client_type = req.body.client_type; var notes = req.body.notes; Transaction.findOne({ name: { […]

奇怪的错误与mongoose

app.get('/showme', function (req, res){ console.log(req.session.user); UserModel.findOne({ user: req.session.user }, function (err, user){ if (err) throw err; console.log(user); res.send('Look'); }); }); 当这个被执行时,我正确接收到terminal中的用户,但之后,突然间应用程序崩溃了,这是错误TypeError: Cannot read property '_id' of null 。 req.session.user被定义,并在应用程序中。 这不是第一次调用UserModel.findOne({ user: req.session.user } ,但是是唯一返回这个错误的!为什么会发生这种情况? 编辑: 这是用户的模式 var userschema = new mongoose.Schema({ user: String, pass: String, mail: String, avatar: String, }); 编辑: 我不知道为什么,但是UserModel.find()没有出现任何错误。 它只发生在UserModel.findOne() 。 编辑: […]

更新MongoDB集合 – JavaScript

我正在尝试更新集合中的值。 用户点击一个button,并将与该button对应的数字发送到服务器以添加到集合中。 我不能得到集合更新,但它在控制台中正常工作,如果我使用db.orders.update() 订单型号: // DB Initiation stuff var orderSchema = new mongoose.Schema({ status: String, rated: Number }); var collection = 'orders'; var Order = db.model('Order', orderSchema, collection); module.exports = Order; 客户端(当点击button时) // starID = 5; id = 50e6a57808a1d92dcd000001 socket.emit('rated', {rated: starID, id: id}); socket.js: var Order = require('../models/orders'); socket.on('rated', function(data) { /* Probably a […]

保存与mongoose

我尝试简单地将我的mongodb基础中的新用户保存到控制器文件中: var mongoose = require('mongoose'); var UserModel = mongoose.model('User'); // signup exports.create = function (req, res) { console.log(req.body); var user = new UserModel({ username: req.body.username, password: req.body.password, email: req.body.email }); user.save(function (err) { if (!err) { return console.log("created"); } else { return console.log(err); } }); } 在debugging模式下,我可以看到user.save()没有执行错误… 我不知道为什么,因为我在用户名/密码/电子邮件字段中获得正确的值。 在这里我的模型文件: var mongoose = require('mongoose'); var Schema […]

node.js上使用mongoose的string的多对多关系

我可以用最简单的演示page文件开始描述我的最佳方式: { name: "Page Name" blocks: { "top-content": 50f0ded99561a3b211000001, "bottom-content": 50f0ded99561a3b211000002 } } 有没有一种方法可以用mongoose来定义这种多对多的关系,这样我就可以用top-content和bottom-content类的string来查找它们了? 与此相关的关系就像在多对多的连接表中包含一个string一样。 重要: 我不想embedded我引用的块,因为它们可以被多个页面引用。