Tag: node mongodb native

Mongo查找查询需要2分钟

我收集了大约75,000个文件。 数据库的总大小约为45GB。 在75k文档中,大约45k是每个900KB(大约42GB),其余的文档大约是120KB。 每个文档都映射到其他集合中的custId ObjectId,并且具有一个索引的timestamp 。 现在我需要为上个月的特定客户获取文档。 这个数字大约是5500个文档。 这个custId有大小约120 KB的小文档。 以下是我的查询: db.mycollection.find( { custId:ObjectId("CUST_OBJECT_ID_HERE"), timestamp:{$gte:one_month_ago_date, $lt:current_date} }).sort({timestamp:-1}) 仍然查询需要2分钟来获取所有logging。 是因为文件的数量还是文件的大小? 有没有办法解决这个问题? 注意:从nodejs发起查询需要2分钟。 如果我在mongo shell上启动它,它会很快返回,但可能是因为它刚刚取得了前50条logging。 当我将.count()附加到mongo shell上的查询时,需要2分钟才能返回count。 更新: 索引细节: "wiredTiger" : { "nindexes" : 3, "totalIndexSize" : 2396160, "indexSizes" : { "_id_" : 1138688, "custId_1" : 598016, "timestamp_1" : 659456 } } 说明输出:(有点) { "queryPlanner" : { […]

while循环来检查自定义id的唯一性

我有一个MongoDB数据库设置了一些具有唯一代码(而不是主键)的对象。 我还应该注意到,我正在使用NodeJS,并且这个代码在我的server.js中连接到MongoDB数据库。 要生成一个新的代码,我随机生成一个,我想检查它是否已经存在。 如果没有,那么我们使用它没有问题,但如果它已经存在,我想要生成另一个代码,并再次检查。 这是我用来检查id是否已经存在的代码: function createPartyId(callback) { var min = 10000, max = 99999; var partyId = -1, count = -1; async.whilst( function () { return count != 0; }, function (callback) { partyId = min + Math.floor(Math.random() * (max – min + 1)); partyId = 88888; getPartyIdCount(partyId, function(num) { count = num; }); […]

同步函数调用nodejs mongodb驱动程序

我有一个处理mongodb数据库的开源项目。 我试图做一个函数,查询数据库来检查是否存在条目。 问题是,当if_exists()返回true或false时,由于mongodb驱动函数是asynchronous的,所以返回undefined。 该文件是Query.js ,我已经尝试了解决scheme在这里解决这个问题什么是正确的方法,使Node.js中的同步MongoDB查询? 但仍然得到一个未定义的结果与get方法。 做这个工作的最好方法是什么? unit testing的输出如下: running unit tests… add query test exists tests: get: undefined {} should be true: undefined get: undefined {} should be false:undefined Captains Logs listening on port 3000 Captains_Logs v0.5.0-21 [ { name: 'rhcp', _id: 50cbdcbe9c3cf97203000002 } ] [ { name: 'os', _id: 50cbdcbe9c3cf97203000001 } ] 您可以在WeaponXI […]

Express.js – 在URL中过滤一个mongodb标识

这个问题启发了这个职位,但在我的情况下,我需要过滤MongoId。 是否可以轻松地进行筛选,因为我需要在每个path中使用它? app.post('/:mongoId(^[0-9a-fA-F]{24}$)', function(req, res){ // Send query based on mongoId }

Mongoose dropDatabase不调用callback函数

dropDatabasecallback有一些问题,它永远不会调用。 这是我的代码: console.log(mongoose.connection.readyState); // prints 1 (connected) var db = mongoose.connection.db; db.dropDatabase(function() { console.log("dropped (callback)"); // never calls }); console.log("dropped"); // prints "dropped" 在Mongod日志中我看到: Sat Oct 5 19:26:44.074 [conn278] dropDatabase test starting Sat Oct 5 19:26:44.088 [conn278] removeJournalFiles Sat Oct 5 19:26:44.104 [conn276] end connection 127.0.0.1:57207 (4 connections now open) Sat Oct 5 19:26:44.105 [conn278] […]

手动closuresmongod.exe不会使用node-mongodb-native引发错误

这是我在这里的第一篇文章。 我正在学习Node和Mongodb。 我已经安装了node-mongodb本地驱动程序,并发现了一些意想不到的事情。 我的脚本在下面,基于官方教程 。 var test; //short cut for later use require('mongodb').MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) { if (err) {return console.log("some error",err);} console.log("database connected"); test = db.collection('test'); test.find().toArray(function(err, items) { if (err) {console.log("some error");} else {console.log("still connected");} }); }); var rep = function () { setTimeout(function () { test.find().toArray(function(err, items) { if (err) {console.log("some error: " […]

MongoDB:查找两个指定键值相等的项目

我有一个mongoDB集合,集合中的一个项目如下所示: { "_id": "52f535b56268a019bd11cc2a", "description": "Some description", "entry_date": "2014-02-07T19:36:21.430Z", "last_update": "2014-02-07T19:36:21.430Z", "r": "samestring", "s": "samestring" } date是ISODate对象。 这个查询返回正确的项目 db.myCollection.find({$where : "this.entry_date < this.last_update"}); 下面的查询返回什么(我期望它返回上述项目): db.myCollection.find({$where : "this.entry_date == this.last_update"}); 和这个查询返回所有项目(我期望它再次返回上述项目): db.myCollection.find({$where :"this.r == this.s"}); 我究竟做错了什么? 谢谢!! – -编辑 – – 所以我试着用如下的小数据进行testing: > db.myCollection.find({},{ _id: 0, start_date: 1, end_date: 1}); { "start_date" : ISODate("2014-02-07T19:36:21.430Z"), "end_date" : […]

使用扩展JSON与node.js mongodb本地驱动程序

我一直在寻找更多的json http://docs.mongodb.org/manual/reference/mongodb-extended-json/,因为我需要我的文档从我的web服务到另一个服务的往返旅程,而不会丢失数据types被用在原始的JavaScript对象(对象ID和date)上。 该节点是否是mongo本机驱动程序实际上是否支持将JavaScript对象序列化为扩展的JSON,并将扩展的JSONparsing为具有正确数据types的JavaScript对象?

从Mongoose(MongoDB,NodeJS Driver)复制集故障转移后,无法自动重新连接到新的PRIMARY

我做了一个简单的NodeJS应用程序,Mongoose作为MongoDB驱动程序。 并连接到一个mongodb副本集。 该应用程序工作正常,直到我closures当前的主要,当PRIMARYclosures时,副本集自动select一个新的主要。 但是,之后,节点应用程序似乎没有响应数据库查询。 代码:数据库连接 var options = { server: { socketOptions: { keepAlive: 1, connectTimeoutMS:30000, socketTimeoutMS:90000 } }, replset: { socketOptions: { keepAlive: 1, connectTimeoutMS : 30000 , socketTimeoutMS: 90000 }, rs_name: 'rs0' } }; var uri = "mongodb://xxx.xxx.xxx.xxx:27017,xxx.xxx.xxx.xxx:27017,xxx.xxx.xxx.xxx:27017/rstest"; mongoose.connect(uri,options); 代码:数据库查询 router.('/test',function(req,res){ var testmodel = new testModel('test') ; testmodel.save(function (err, doc,numberAffected) { if (err) […]

在MongoDB MapReduce作用域中使用部分应用的函数

我在MongoDB MapReduce操作中使用了一个通用映射函数,其中映射本身是一种元运algorithm则,运行通过scope传递给它的某些函数。 这对正常的JS函数工作正常,但我也想传入部分应用函数,这是我遇到的问题。 我用各种configuration填充mrScope ,包括我需要部分应用的function,如下所示: mrScope.operator = operators.getOperator(opSettings.arg1); 我把(promisified)mapReduce称为: conn.mongoClient.collection(input.collection).mapReduceAsync(map, reduce, { query : input.rawQuery, scope : { fScope: mrScope }, jsMode : true, out : 'testMe' }) getOperator应该返回一个部分应用的函数。 该函数的最后一个参数总是在map传递,如下所示: fScope.operator.call(null, operatorInput); 在这一点上,我可以从MongoDB得到各种错误,这取决于我如何尝试在getOperator创build部分应用程序。 这里的相关部分是(为了清楚起见,它有打字稿typedef): export function getOperator(arg: number): OperatorFunction { if (arg === 0) { throw 'arg must not be 0'; } else { return […]