mongodb-query

How can I solve MongoWaitQueueFullException?

淺唱寂寞╮ 提交于 2019-12-05 19:49:55
I run a java program which is a thread executor program that inserts thousands of documents to a table in mongodb. I get the following error Exception in thread "pool-1-thread-301" com.mongodb.MongoWaitQueueFullException: Too many threads are already waiting for a connection. Max number of threads (maxWaitQueueSize) of 500 has been exceeded. at com.mongodb.PooledConnectionProvider.get(PooledConnectionProvider.java:70) at com.mongodb.DefaultServer.getConnection(DefaultServer.java:73) at com.mongodb.BaseCluster$WrappedServer.getConnection(BaseCluster.java:221) at com.mongodb.DBTCPConnector

Can I set Mongoid query timeout? Mongoid don't kill long time query

丶灬走出姿态 提交于 2019-12-05 18:49:07
Mongoid don't have timeout option. http://mongoid.org/en/mongoid/docs/installation.html I want Mongoid to kill long time queries. How can I set Mongoid query timeout? If I do nothing, Mongoid wait a long time like the below. mongo > db.currentOp() { "opid" : 34973, "active" : true, "secs_running" : 1317, // <- too long! "op" : "query", "ns" : "db_name.collection_name", "query" : { "$msg" : "query not recording (too large)" }, "client" : "123.456.789.123:46529", "desc" : "conn42", "threadId" : "0x7ff5fb95c700", "connectionId" : 42, "locks" : { "^db_name" : "R" }, "waitingForLock" : true,

set default values to mongoose arrays in node js

六眼飞鱼酱① 提交于 2019-12-05 18:44:19
In my model definition, I have: appFeatures: [{ name: String, param : [{ name : String, value : String }] }] I want to set default value to appFeatures, for example: name: 'feature', param: [{name:'param1',value:'1'},{name:'param2',value:'2'}] I tried to do it by appFeatures : { type : Array , "default" : ... } But its not working, any ideas? Thanks Mongoose allows you to "separate" schema definitions. Both for general "re-use" and clarity of code. So a better way to do this is: // general imports var mongoose = require('mongoose'), Schema = mongoose.Schema; // schema for params var

Mongo / Mongoose Aggregation - $redact and $cond issues

天大地大妈咪最大 提交于 2019-12-05 18:27:30
I was fortunate enough to get an awesome answer to another SO question Mongo / Mongoose - Aggregating by Date from @chridam which given a set of documents like: { "_id" : ObjectId("5907a5850b459d4fdcdf49ac"), "amount" : -33.3, "name" : "RINGGO", "method" : "VIS", "date" : ISODate("2017-04-26T23:00:00Z"), "importDate" : ISODate("2017-05-01T21:15:49.581Z"), "category" : "Not Set", "__v" : 0 } { "_id" : ObjectId("5907a5850b459d4fdcdf49ba"), "amount" : -61.3, "name" : "Amazon", "method" : "VIS", "date" : ISODate("2017-03-23T00:00:00Z"), "importDate" : ISODate("2017-05-01T21:15:49.592Z"), "category

$push equivalent for map in mongo

六眼飞鱼酱① 提交于 2019-12-05 18:23:53
We can use $push (to add an element into an array) in update to atomically update a single document containing the array However, I could not find a way to atomically add a new key to a map in a document. I could * read the document, * read the map in it, * update the map in my code and * update the document in my code. But that is not atomic. I am only dealing with a single document but that document has a map. Is there a way I can update (add a new key) map atomically? Dot notation with the $set operator is how you address individual elements. Take the following document: { "_id": 1, "map":

arrayFilters in mongodb

感情迁移 提交于 2019-12-05 18:22:41
I have the following schema. { posts: [ { _id: '5ayuunbdsyuuuyut778' replies: [{ _id: "67hfudj7e9whduu888", text: "something" }] } ] } I want to update the text in particular reply. I am using mongoose. I have written the query as follows Post.findOneAndUpdate( {'posts.replies._id': _id}, {$set: {'posts.$[post].replies.$[reply].text': "something1"}}, { arrayFilters: [{'post._id': postId}, { 'reply._id': _id }]} ) This query is not updating the document. Am I missing something? Do I need to cast ids using ObjectId You need to use new: true to get the updated value and cast id to mongoose

How to do nested $lookup search in MongoDB?

半腔热情 提交于 2019-12-05 18:00:55
I have 3 collections: positions: +------------------+----------------------+-----------------------+ | position_id | company_id | position_name | +------------------+----------------------+-----------------------+ | 1 | 1 | position 1 | +------------------+----------------------+-----------------------+ | 2 | 2 | position 2 | +------------------+----------------------+-----------------------+ companies: +------------------+----------------------+-----------------------+ | company_id | industry_id | company_name | +------------------+----------------------+-----------------------+ | 1 | 1 |

Find first element in nested array that match conditions

本秂侑毒 提交于 2019-12-05 16:18:33
I have following documents: doc1: { 'array': [ {'field': 'ABC', 'enabled': 'false'}, {'field': 'BCD', 'enabled': 'true'}, {'field': 'DEF', 'enabled': 'false'}, {'field': 'XYZ', 'enabled': 'true'}, ] } doc2: { 'array': [ {'field': 'ABC', 'enabled': 'true'}, {'field': 'BCD', 'enabled': 'true'}, {'field': 'DEF', 'enabled': 'false'}, {'field': 'XYZ', 'enabled': 'true'}, ] } I'm performing search by particular field. I want to get all documents that have this field enabled, and there are no other fields enabled before this (in the list). For ex.: search for field: BCD , enabled: true - should

How to return just the matched elements from a mongoDB array

半世苍凉 提交于 2019-12-05 14:50:18
I've been looking for this question one week and I can't understand why it still don't work... I have this object into my MongoDB database: { produc: [ { cod_prod: "0001", description: "Ordenador", price: 400, current_stock: 3, min_stock: 1, cod_zone: "08850" }, { cod_prod: "0002", description: "Secador", price: 30, current_stock: 10, min_stock: 2, cod_zone: "08870" }, { cod_prod: "0003", description: "Portatil", price: 500, current_stock: 8, min_stock: 4, cod_zone: "08860" }, { cod_prod: "0004", description: "Disco Duro", price: 100, current_stock: 20, min_stock: 5, cod_zone: "08850" }, { cod

Updating a deep record in MongoDb

百般思念 提交于 2019-12-05 14:28:40
I have this record in MongoDb, and am using the native API: { "_children" : { "addressesR" : [ { "id" : ObjectId("530eea01071bd1a53065c1a6"), "personId" : ObjectId("530eea01071bd1a53065c1a4"), "street" : "ivermey", "city" : "perth", "_children" : { } }, { "_children" : { "configId" : { "a" : { "_children" : [ { "b" : 10 }, { "b" : 20 } ] } } }, "city" : "perth", "configId" : ObjectId("530eea01071bd1a53065c1a3"), "id" : ObjectId("530eea01071bd1a53065c1a5"), "personId" : ObjectId("530eea01071bd1a53065c1a4"), "street" : "bitton" } ], } } I need to update, in one query, that nested 'b' to 30. I