Tag: mongodb

使用mongoose 4.11.0进行组查询

我想用最后一个版本的mongoose做一个例子: Patient.group({gender:true}) .then((result)=>{ console.log(result); }); 病人是模型,你知道这是怎么回事?

在NodeJS中stream到MongoDB

我使用模块streamToMongoDB的node.js从Web APIstream到MongoDB。 var streamToMongoDB = require("stream-to-mongo-db").streamToMongoDB; var JSONStream = require("JSONStream"); var request = require("request"); var fs = require("fs"); // where the data will end up var outputDBConfig = { dbURL : "mongodb://user:password@0.0.0.0/test", collection : "temperature" }; // create the writable stream var writableStream = streamToMongoDB(outputDBConfig); // create readable stream and consume it request("http://0.0.0.0:8081/getTemp") .pipe(JSONStream.parse('*')) .pipe(writableStream); […]

Nodejs Mongodb第二次sorting()第一次sorting()的结果

格式想要出现 – msg – 9 … msg – 17 msg – 18 msg – 19 从这个function mongo.connect(mongourl, function (err, db) { var collection = db.collection('chat') var stream = collection.find().sort({ _id : -1 }).limit(10).stream(); stream.on('data', function (chatt) {clients[socket.id].emit('chat message', chatt.content); }); });}); 但这种sorting只能给我 – msg – 19 msg – 18 msg – 17 … msg – […]

如何调用来自MongoDB的函数

这是我的robomongo文件 { "_id" : ObjectId("##########"), "actionname" : "testaction", "actiontype" : "database.action", "isshortworkflow" : true, "processstartedmessage" : "", "databaseUserName" : "####", "databasePassword" : "", "queryTemplate" : "Select * from shop where name=parameters.get("itemName")", "databaseType" : "MYSQL", "resultTemplate" : " parameters.get("itemName") + 'has quantity of' + result[0].get('quantity')" } 这里的queryTemplate字段是有name = parameres.get(“itemName”)。这是我的java代码中的一个本地函数,它将返回为“item1”。 问题是,因为它将来自mongo db,所以不会执行paramerters.get(“itemName”)函数。 有没有办法使用从mongodb返回的string执行该函数。如何在mongodb内部实现?

在嵌套模型中使用mongoose-auto-increment插件

我正在尝试在每次调用api调用时增加procedureid doctorId和doctorId的值。 我正在使用下面的语法。 但是,当我第二次通过浏览器调用api时,它提供了一个错误Treatment.procedureid_1 dup key 。 我可以看到,通过自动增量创build的identityCounter集合中的procedureID和doctorId的值正在增加。但是,在各自的架构 你能帮我解决这个问题吗? var mongoose = require('mongoose'); var autoIncrement = require('mongoose-auto-increment'); var hospitalDoctorSchema = new Schema({ Treatment: { procedureid: { type: Number,required: true, unique: true,default: 0 }, doctor: { doctorId: { type: Number, required: true, unique: true, dropDups: true, default: 0 }, }, }, updated_at: { type: Date, required: […]

错误被抛出,但错误响应对象在Mongoose中为空

我正在尝试向我的API发送请求。 我的代码是这样的 app.post('/api/create', (req, res, next) => { if (!req.headers || !req.headers.authorization) { return res.status(500).json({ status: 'error', err: 'No authorization header' }); } const bits = req.headers.authorization.split(' '); const scheme = bits[0]; const token = bits[1]; jwt.verify(token, 'secret', function(err, decoded) { if (!!err) { return res.status(400).json({ status: 'error', err: 'Invalid credentials.' }); } // const […]

如何用asynchronousvalidation更新mongoose模型(node / koa2)

从客户端,用户有一个表格填写他们可以更新他们的电子邮件或密码。 他们必须input当前密码才能validation请求。 之后,如果电子邮件地址正在被修改,那么电子邮件validation器应该运行以检查新的电子邮件地址是否已经被注册到另一个用户。 所以,在用户从客户端发送请求后,我得到以下信息: { userId: 'This is the ID of their entry in the database', currentPassword: 'Current password to check against one stored in database', newPassword: 'New password, will be blank if user has not requested a new password', email: 'Email address, will be the same if user has not requested a new email' […]

我不能从Node控件和mongodb中使用get方法从html控件中获取数据

代码中的问题 var userID = req.userid; var pwd = req.pwd; console.log("userid = " + userID + "pass = " + pwd); 控制台显示的值未定义,而不是input数据 控制台显示的值未定义,而不是input数据 我想从一个html文件中获取数据,并使用get方法插入到mongo数据库中。 但我无法从文本框中获取数据。 在nodejs(index.js)中的代码 const express = require('express'); const path = require('path'); const bodyparser = require("body-parser"); const mongoose = require('mongoose'); const app = express(); app.use(bodyparser()); app.use(bodyparser.urlencoded({ extended: false })); app.use(bodyparser.json()); app.set('port', (process.env.PORT || 1000)); […]

在Mongodb Nodejs中分页

是否有任何方法来获得查找操作中的文档总数以及MongoDB查询中的跳过和限制 MongoClient.connect(Config.dbURI, function (err, db) { if (!err) { console.log("We are connected"); console.log(uniqueId) db.collection(dbName).find({'uniqueId': uniqueId, 'isDeleted': false}) .sort({modifiedDateISO: -1}) .limit(parseInt(limit)) .skip(parseInt(limit * page)) .toArray((errFindChat, dataFindChat) => { console.log(errFindChat, dataFindChat); }); });

查询Mongo数据库

我需要对我的mongo数据库中的以下条目执行查询: { "_id" : ObjectId("597b19512a5b1c3258e6440e"), "fdata" : [ { "type" : "header", "subtype" : "h1", "label" : "Date Of Commencement" }, { "type" : "paragraph", "subtype" : "p", "label" : "The partnership business shall be deemed to have commenced on and from :" }, { "type" : "date", "label" : "Date Field", "description" : "Enter […]