Tag: mongoose

像Trello这样的项目,在Mongoose中创build一个合适的数据库

我正在尝试创build像Trello这样的项目。 有人可以告诉我如何创build一个卡的数据库,因为我首先想出了列表模型,我添加一个字段: card: { type: Array }, 现在的问题是,它会没事的。 因为我认为通过在棋盘上操作,我将更容易按顺序设置牌。 但后来我想添加拖动和移动卡从一个列表到另一个列表。 后来我想添加添加照片到卡上的选项,现在的问题是作为列表中的模型或创build一个单独的模型卡?

MongoDB群集中的并发问题

我到了一个需要扩展应用程序的地步,不幸的是,当我编写应用程序时,我从来没有想过集群。 现在我遇到了一些问题,我不确定为了避免这样的问题会做些什么。 我将展示两个相当简单的代码示例: 例1: 如果我在8个实例上运行这个函数,它可能会重复select相同的configuration文件(因为它们是有序的)。 更新那些很长时间没有更新的configuration文件是有道理的,但是有没有某种“locking”可以防止其他实例在完全相同的文件上工作? // Select 100 least updated profiles and update them PlayerProfile.find().sort({ updated_at: 1 }).limit(100).then((playerProfiles) => { // Code which would update these 100 selected profiles }) 例2: 我在我的MongoDB中有1000个账号的集合,每个实例应该有100个账号。 没有实例被允许使用完全相同的帐户凭证。 如何确保运行多个实例时的情况? Account.find({}, 'player_id token').limit(this.clientQuantity).then((accounts) => { logger.info(`Using ${accounts.length} accounts from the database`) for (let i = 0; i < accounts.length; i++) […]

gridfs-stream和mongoose> = 4.11.0连接设置

我一直在使用与mongoose老版本(<4.11.0)的gridfs-stream与以下设置: var grid = require("gridfs-stream"); var mongoose = require("mongoose"); mongoose.connect(connectionString); grid.mongo = mongoose.mongo; var gfs = grid(mongoose.connection.db); 所有这些设置正常工作。 在更新到mongoose4.11.11之后,应将mongoose连接设置更改为(第三行): mongoose.connect(connectionString, {useMongoClient: true}); 但是,现在mongoose.connection.db不再被定义。 上面的代码应该如何改变才能使其重新工作? 非常感谢。

保存第一次login历史logging后,ExpressJS应用login失败

我使用PassportJS,MongoDB(Mongoose)和JSON Web令牌实现了一个ExpressJS应用程序。 在成功login路线实施 await user.insertLoginTime(); const token = user.generateJwt(); res.status(200).json({ token }); Mongoose模型方法'insertLoginTime' userSchema.methods.insertLoginTime = async function() { try { const presentTime = new Date().getTime(); await this.loginHistory.push(presentTime); await this.save(); return; } catch (error) { throw new Error(error); } }; 首先login成功,“邮递员”收到令牌,但在接下来的尝试中返回无效的密码错误。 删除'insertLoginTime'方法成功login多次尝试。 在“insertLoginTime”实现中是否有任何错误?

使用mongoose更新mongoDb中数组内部的对象

我正在MongoDB中处理MongoDB集合中的数组内部的更新对象值。 我的collections就像 { "_id": ObjectId("59b7e839200a5c00ee2d2851"), "player": "New", "playesList": [ { "_id": ObjectId("59b2a4f749fee40959e556d3"), "name": "abcd", }, { "_id": ObjectId("59b2a4f749fee40959e556d4"), "name": "pqrs", } ] } 现在我想更新ID为59b2a4f749fee40959e556d3 (我的意思是当前第一个玩家的名字是abcd),玩家的名字是59b7e839200a5c00ee2d2851 ,玩家New 。 所以我试图用这个查询更新 play.update( { '_id': '59b7e839200a5c00ee2d2851', 'player': 'new', 'playesList._id': '59b2a4f749fee40959e556d3' }, { '$set': { 'playesList.$.name': 'wxyz' } }, function(error, success) { console.log(error, success); } ) 但是在这里我得到了像null { ok: 1, […]

如何使用mongoose羽毛适配器编写一个聚合体?

我是feathersjs框架的新手,并试图写聚合查询它不能正常工作。 hook.app.query = { lookup: { from: "orders", localField:"serviceLocationId", foreignField:"serviceLocationId", as: "orders" }, match: { serviceLocationId : { $in: Array.from(new Set(reqArr)) } }, limit: 14 } hook.app.service('servicelocations') .find(hook.app.query) .then(result => { console.log(result) })

lodash mongoose ObjectId数组的联合

我有2个包含ObjectId项目的数组: array1 array2 我想创build这两个数组之间的联合。 为此,我正在运行: let res = _.union(array1, array2); 但res包含重复的ObjectId。 我如何解决这个问题?

找不到mongoose模式

我尝试创build一个专用的mongoosecreateConnection。 Node.js融合: MyModel = conn.model('Profile',profileSchema), profileSchema未定义。 但是我哪里错了? //my db.js const mongoose = require('mongoose'); const conn = mongoose.createConnection = ("mongodb://localhost:27017/myDatabase"), MyModel = conn.model('Profile', profileSchema), m = new MyModel; m.save(); //works; if (process.env.NODE_ENV === 'production') { conn = process.env.MONGODB_URI; } require('./profiles) 这里是我的模型页面的其余部分: // my profile.js // JavaScript source code const mongoose = require('mongoose'); const profileSchema = new […]

Monogdb崩溃使用节点js的多个连接

Server.js文件: var option = { server: { poolSize: 10, socketOptions: { keepAlive: 300000, connectTimeoutMS: 30000, auto_reconnect:true } }, replset: { poolSize: 10, socketOptions: { keepAlive: 300000, connectTimeoutMS: 30000, auto_reconnect:true } } }; var mongoURI = 'mongodb://127.0.0.1:27018/duplicacySecond'; mongoose.connect(mongoURI, option).then(function(){ console.log("sucessfully connected to mongoDB"); }, function(err) { if(err){ console.log('not connected to the database : '+err); } }); […]

如何正确创build像trello,Mongoose和Angularjs的卡片显示

我不知道,我已经尝试了一切。 我想这样做下的列表中添加和显示卡的顺序和显示从上升位置。 我必须这样做,以便以后可以添加拖放操作。 这将计算我放置的项目和下面的索引项目的平均位置。 我不能在ng-repeat循环中进行sorting,因为稍后显示的索引不匹配数组元素。 我试图在nodejssorting,但没有按照它应该sorting。 在mongoose数据库中,我这样做了:\ 名单 ** name:{type:String,maxlength:20,required:true},** 卡 var CardSchema = new Schema({ list: { type: Schema.Types.ObjectId, ref: 'List' }, name: { type: String, maxlength: 20, required: true }, position: { type: Number }, // description: { type: String, maxlength: 300 }, updated: { type: Date, default: Date.now }, created: { type: […]