Tag: reactjs mongoose

在mongoose节点js中添加键值对数据

我在Mongoose中有一个模式,如下所示: const SocketDetailsUserSchema = new mongoose.Schema({ userId: String, socketValue: [{ id: String, data : String }], isDeleted: Boolean, dateCreated: Date, updateAt: Date }); 我想以数组格式在键值对中插入socketValue的数据。 应该看起来像 { "_id" : ObjectId("5a12809c7f7afb1e3626857f"), "userId" : "59eee19696fe6560cd54a081", "socketValue" : [{"id":"5a05855b10600e4aa5b3a48e" , "value" : "123" }],[{"id":"5a0ae037a90746c249b6c1f7" , "value" : "456" }]", "isDeleted" : false "__v" : 0 } 这是mongoose数据格式。 我如何可以像这样在mongoose中插入数据? 我也很困惑,我应该如何发布postman的数据在这里插入数据?

User.save到DB(使用mongoose)不是一个函数

UserModelVk.findOne({vkontakteId: profile.id}, function(err, vkUser){ if(err){ return done(err) } if(!vkUser){ const user = new UserModelVk({ vkontakteId: profile.id, name: profile.displayName, access_token: params.access_token }) user.save(function(err) { if (err){ log.error(err) } localStorage.setItem('username', user.vkontakteId); localStorage.setItem('key', user.access_token) return done(err, user); }); } else { vkUser = { access_token: params.access_token } vkUser.save(function(err) { if (err){ log.error(err) } localStorage.setItem('key', vkUser.access_token) return done(err, vkUser); […]

在NodeJS的两个位置之间获取logging

如何通过mongoose获取NodeJS中两个位置的logging。 我正在使用函数来查找具有function的logging, getAllEvent: function (locationReq, callback) { Events.find({ location: { $near: { $geometry: { loc: locationReq }, $maxDistance: 0, $minDistance: 250 } } }, {isDeleted: false}, function (error, data) { callback((error) ? {} : (data == null) ? {} : data); }); }, 这个函数返回空值。 特定logging的位置也存储在数据库文档的集合中。 在LocationReq中将发送两个位置值。 如果logging在两个位置之间,我想要logging。 数据库文件如下, { "_id" : ObjectId("59db3a1e56e60915086fb73f"), "eventName" : "5643213246", […]

数小时后,数据不应该显示NodeJS

我有一个types的数据收集有eventDateTime字段。 6小时后,数据应显示在列表中,6小时后不应列出。 在这里,我发送给你查询, Events.find({$and: [{eventDateTime: {$lt: 21600}}, {isDisabled: false}, {isDeleted: false} ]}, function (error, data) { callback((error) ? {} : data); }) ; 我怎样才能在几秒钟内转换eventDateTime和比较秒,因为它是6个小时?

发布到数据库时,我得到一个“发送错误后无法设置标头”

在这个问题中,我发布了完整的数据stream来完成销售,因为我不知道错误在哪里。 在我的应用程序中,在Checkout组件中调用一个名为handlePay()的函数,该函数又调用一个名为makeSale()的动作创build器。 makeSale()然后向router.js中的服务器发出一个POST请求,该请求将使用mongoose处理数据库中的这个销售。 从控制台读取错误 “/Users/marcushurney/Desktop/POS/node_modules/mongodb/lib/utils.js:98 process.nextTick(function(){throw err;}); ^ 错误:发送后无法设置标题。“ 我不确定这个错误是否存在于与router.js或前端其他地方的数据库进行通信的代码中。 前端的组件叫做Checkout.jsx,处理销售的function是handlePay(),其关联的动作创build者是makeSale()。 Checkout.jsx handlePay: function() { var props = { user_id: this.props.activeUser._id, //This sale will belong to the user that is logged in (global state) items: [], //All the items in the cart will be added to the sale below (global state) total: this.props.cartTotal //Total price […]

使用Mongoose和Redux删除logging

当用户按下给定logging的button时,我想删除我的mongoDB中的logging。 以供参考: 我有我所有的mongoose和redux代码设置,但我得到这个错误: 这是我的行动: //deletes a survey when user clicks button export const deleteSurvey = (surveyId) => async dispatch => { const response = await axios.delete("/api/surveys", surveyId); dispatch({ type: FETCH_SURVEYS, payload: response.data }); }; 这是我的路由处理程序: app.delete("/api/surveys", requireLogin, (req, res) => { Survey.findByIdAndRemove(req.surveyId, (err, survey) => { let response = { message: "Survey successfully deleted", }; […]