Tag: mongodb

Node.js – 与Mongoosebuild立关系

我有2个Schema, Custphone和Subdomain 。 Custphone belongs_to Subdomain和Subdomain has_many Custphones 。 问题在于使用Mongoose创build关系。 我的目标是做:custphone.subdomain并获取Custphone所属的子域。 我在我的模式中有这个: SubdomainSchema = new Schema name : String CustphoneSchema = new Schema phone : String subdomain : [SubdomainSchema] 当我打印custphone结果时,我得到这个: { _id: 4e9bc59b01c642bf4a00002d, subdomain: [] } 当Custphone结果在MongoDB中有{"$oid": "4e9b532b01c642bf4a000003"} 。 我想做custphone.subdomain并获取custphone.subdomain的子域对象。

删除mongodb的日志文件是否安全?

如果我删除3.1G日志文件, sudo service mongodb restart将失败。 但是,这个文件占用太多的空间。 我怎么解决这个问题? 我怎样才能删除它? bash$ du -sh /var/lib/mongodb/* 4.0K _tmp 65M auction_development.0 128M auction_development.1 17M auction_development.ns 3.1G journal 4.0K mongod.lock

mongodb组值由多个字段组成

例如,我有这些文件: { addr: 'address1' book: 'book1' }, { addr: 'address2' book: 'book1' }, { addr: 'address1' book: 'book5' }, { addr: 'address3' book: 'book9' }, { addr: 'address2' book: 'book5' }, { addr: 'address2' book: 'book1' }, { addr: 'address1' book: 'book1' }, { addr: 'address15' book: 'book1' }, { addr: 'address9' book: 'book99' }, […]

嘲笑node.js中的数据库?

如何在我的node.js应用程序中模拟出数据库,在这种情况下,使用mongodb作为博客REST API的后端? 当然,我可以将数据库设置为特定的testing数据库,但是我仍然可以保存数据,而不是只testing我的代码,而且还testing数据库,所以实际上我并没有进行unit testing,而是进行了集成testing。 那么应该怎么做? 创build数据库包装作为应用程序和数据库之间的中间层,并在testing中replaceDAL? // app.js var express = require('express'); app = express(), mongo = require('mongoskin'), db = mongo.db('localhost:27017/test?auto_reconnect'); app.get('/posts/:slug', function(req, res){ db.collection('posts').findOne({slug: req.params.slug}, function (err, post) { res.send(JSON.stringify(post), 200); }); }); app.listen(3000); // test.js r = require('requestah')(3000); describe("Does some testing", function() { it("Fetches a blogpost by slug", function(done) { r.get("/posts/aslug", function(res) { […]

mongodb数据库在mac上的位置

我对mac和mongodb都有点新鲜感。 我有一个奇怪的疑问,访问在mac上使用mongodb创build的数据库? 我知道,在Windows中有一个名为c:\ data \ db的文件夹,我的数据库文件存储在这里。 在mac中,如何以及在哪里存储数据库。 我记得做过类似的事情 sudo mkdir -p /data/db sudo chown `id -u` /data/db 在mac上创build这样一个文件夹,但是我没有在这个文件夹中find任何数据库文件,虽然我创build了一个数据库。 数据库文件在mac上保存在哪里? 任何帮助将非常感激。

在Mongoose中引用另一个模式

如果我有两个模式,如: var userSchema = new Schema({ twittername: String, twitterID: Number, displayName: String, profilePic: String, }); var User = mongoose.model('User') var postSchema = new Schema({ name: String, postedBy: User, //User Model Type dateCreated: Date, comments: [{body:"string", by: mongoose.Schema.Types.ObjectId}], }); 我试图把它们连接在一起,就像上面的例子,但我不知道如何做到这一点。 最终,如果我可以做这样的事情,那会让我的生活变得很容易 var profilePic = Post.postedBy.profilePic

是否有一个样本MongoDB数据库沿世界线MySql?

作为Mongo的新手,我正在寻找一个可导入和使用的MongoDB数据库示例。 沿着世界的线为MySQL或Northwind的MSSQL的东西。 有一个吗? (我在http://www.mongodb.org找不到任何提及,也没有我的search帮助)

什么是在Mac OS X上停止mongod的干净方式?

我正在运行mongo 1.8.2并试图看看如何在Mac上彻底closures它。 在我们的Ubuntu服务器上,我可以用mongo shell彻底closuresmongo: > use admin > db.shutdownServer() 但在我的Mac上,它并没有杀死mongod进程。 输出显示它应该是关机,但是当我ps -ef | grep mongo它显示了我一个活跃的过程。 另外,我仍然可以打开一个mongo shell并查询我的dbs,因为它从来没有关机。 本地db.shutdownServer()的输出是: MongoDB shell version: 1.8.2 connecting to: test > use admin switched to db admin > db.shutdownServer() Tue Dec 13 11:44:21 DBClientCursor::init call() failed Tue Dec 13 11:44:21 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1 […]

为什么Mongoose既有模式又有模型?

两种物体似乎彼此如此接近,以致两者都感觉多余。 同时拥有模式和模型有什么意义?

MongoDB和CouchDB是完美的替代品吗?

我的手还没弄脏,既没有CouchDB也没有MongoDB,但我很快就要这样做了…我也读了一些关于这两个系统,它看起来像我涵盖了相同的情况…或者我错过了一个关键的特色? 我想在下一个项目中使用基于文档的存储,而不是传统的RDBMS。 我也需要数据存储 处理大的二进制对象(图像和video) 自动将其自身复制到物理上分离的节点 使得需要额外的RDBMS是多余的 都同样适合这些要求? 谢谢!