mongodb-java

MongoDB Spark Connector - aggregation is slow

非 Y 不嫁゛ 提交于 2021-02-06 12:49:07
问题 I am running the same aggregation pipeline with a Spark Application and on the Mongos console. On the console, the data is fetched within the blink of an eye, and only a second use of "it" is needed to retrieve all expected data. The Spark Application however takes almost two minutes according to the Spark WebUI. As you can see, 242 tasks are being launched to fetch the result. I am not sure why such an high amount of tasks is launched while there are only 40 documents being returned by the

How to create the Mongo database connection in context.xml in Java web project?

﹥>﹥吖頭↗ 提交于 2021-01-29 22:31:10
问题 Although there are many proper tutorials to show how to connect relational database in Java, I really in doubt with the MongoDB mechanism working with Java. Normally people would create a connection in context.xml to interact with a relational database with JSP/servlet to do web project. However, with NoSQL database, I don't quite get any resources on how to perform this connection in a nice constructed way rather than many resources with framework lately and working seamlessly. If any

How to create the Mongo database connection in context.xml in Java web project?

元气小坏坏 提交于 2021-01-29 22:14:43
问题 Although there are many proper tutorials to show how to connect relational database in Java, I really in doubt with the MongoDB mechanism working with Java. Normally people would create a connection in context.xml to interact with a relational database with JSP/servlet to do web project. However, with NoSQL database, I don't quite get any resources on how to perform this connection in a nice constructed way rather than many resources with framework lately and working seamlessly. If any

Returning both old and new entities from Spring/MongoDB findAndModify

穿精又带淫゛_ 提交于 2021-01-26 07:15:20
问题 We're using MongoDB via Spring Data and rely on the findAndModify operation to update existing entities or create new ones. In the findAndModify we can configure to return old state of the entity or the new one using returnNew(...) . Is there some way to return both old and new entities from findAndModify ? We need to compare entity states before and after update, this is why we need both instances. At the moment we're resorting to requireNew(false) and then manually update a copy of the old

Managing Mongodb connections in Java as Object Oriented

寵の児 提交于 2020-08-10 19:45:50
问题 How Do I properly Manage mongo connections using multiple classes ? For example I have 4 classes that manages 4 collections. Collection1.class Collection2.class Etc.. What I do is creating a connect and close method in each class which by the time slows the connection of some transactions in the app What would be the best way to connect the app to db once and start using all the classes instances other than creating object of each class and connecting each one separately ? 回答1: You are

mongodb Java Driver - $group with multiple fields

六眼飞鱼酱① 提交于 2020-06-29 04:33:33
问题 My goal is to create a pipeline using the aggregation framework to group my data and then use this pipeline with the java driver. MongoDB v4.0.3 I created the following pipeline using MongoDB Compass (reduced to the important part): [{ $group: { _id: { year: '$year', month: '$month', day: '$day', prodName: '$prodName', actionName: '$actionName' }, actionCount: { $sum: 1 } } } ] This resulted in the following (generated) Java code: collectionName.aggregate( Arrays.asList( group(and(eq("year",

List of all collections in mongo database in java

不问归期 提交于 2020-06-27 09:08:56
问题 how can I get a list of all the collections in the database? database - mongodb; language - java; ide - eclipse; 回答1: Getting A List Of Collections Each database has zero or more collections. You can retrieve a list of them from the db (and print out any that are there) : Set<String> colls = db.getCollectionNames(); for (String s : colls) { System.out.println(s); } Edit : As suggested in @Andrew's answer, updated java client uses this : /** * Gets the names of all the collections in this