Tag: mongodb indexes

独特和稀疏的模式级索引MongoDB和Mongoose

我试图创build一个模式的两个领域的索引,在MongoDB中使用Mongoose是唯一和稀疏的,如下所示: var ArraySchema = new Schema ({ user_id: {type: mongoose.Schema.Types.ObjectId, ref:'User'}, event_id: {type: mongoose.Schema.Types.ObjectId, ref:'Event'} }, {_id:false}); ListSchema.index({user_id:1, event_id:1}, {sparse:true, unique:true}); 然后将其用于用户架构中的数组中,如下所示: var User = new Schema({ arrayType1 : { type: [ArraySchema] }, arrayType2 : { type: [ArraySchema] }, arrayType3 : { type: [ArraySchema] } //More specifications for user schema… }); 但是,当试图保存没有array字段的多个用户时,重复字段会引发错误。 Mocha中的错误与此类似: array.event_id_1 dup […]

GeoJSON和Legacy坐标对在mongoDb方面有什么区别?

我想用mongoDb的$ geoNear聚合运算符来计算用户从当前位置的距离,方法如下: '$geoNear': { near: currentLocation, distanceField: 'distance', spherical: true, } 随着currentLocation是这样的: { "type" : "Point", "coordinates" : [ -122.1575745, 37.4457966 ] } 我的collections是以下types(使用mongoose): users = [{ …. location : { // GeoJSON Point or I think it is 😉 type: { type: String }, coordinates: [] } …. }] 我正在使用索引(再次mongoose的语法): userSchema.index({ location: '2dsphere' }); […]

部分索引在mongodb / mongoose

在稀疏索引文档中,我find关于mongodb 3.2部分索引的注释 在版本3.2中更改:从MongoDB 3.2开始,MongoDB提供了创build部分索引的选项。 部分索引提供了稀疏索引function的超集。 如果您使用的是MongoDB 3.2或更高版本,则部分索引应优先于稀疏索引。 部分索引是非常有用的,我想在我的项目中使用它们。 mongoose可以用它们吗?

监测MongoDB的“后台操作”?

编辑:基本上我正在寻找一些关于如何理解我的MongoDB实例上运行的后台操作的提示,并可能在必要时减less/禁用它们,以免它们干扰运行testing。 我已经尝试了mongostat和mongotop但没有find任何帮助我了解后台操作正在运行以及正在启动的操作。 在开始运行我的testing之前, db.currentOp()在运行时始终返回一个空数组。 我经常运行testing,同时开发节点(摩卡,黄瓜)。 从昨天开始,大约有25%的服务器初始化尝试连接到mongodb时出现以下错误: **Unhandled rejection MongoError: exception: cannot perform operation: a background operation is currently running for collection** somecollection at Function.MongoError.create (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11) at /somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:793:66 at bound (domain.js:254:14) at runBound (domain.js:267:12) at Callbacks.emit (…/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3) at null.messageHandler (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23) at Socket.<anonymous> (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:294:20) at Socket.emit (events.js:107:17) at readableAddChunk (_stream_readable.js:163:16) at Socket.Readable.push (_stream_readable.js:126:10) at TCP.onread (net.js:538:20) 在运行testing之前,我们使用pow-mongodb-fixtures来清除数据库并填充一些基本数据,这就是发生这种情况的原因。 […]