mongo-java

Difference between cursor.count() and cursor.size() in MongoDB

强颜欢笑 提交于 2019-12-30 05:46:27
问题 What is the difference between the cursor.count() and cursor.size() methods of MongoDB's DBCursor ? 回答1: From the Javadoc of the MongoDB Java Driver, it says : DBCursor.count(): Counts the number of objects matching the query. This does not take limit/skip into consideration. DBCursor.size(): Counts the number of objects matching the query. This does take limit/skip into consideration. 回答2: More than an answer I'd like to point out an issue that our team faced "mixing" this two. We had

Mongodb count with queries have poor performance

十年热恋 提交于 2019-12-25 05:57:08
问题 Counting the number of records in a collection that is matched by a query even on an indexed field takes too much time. For example lets say there is a collection consists of 10000 records, and there is an index on the creationDate field of this collection. Getting the last ten records from the collection is faster than counting the number of records created on the last day. It takes more than 5 seconds, sometimes even up to 70 seconds to return the result of the count query. Do you have any

Mongodb count with queries have poor performance

断了今生、忘了曾经 提交于 2019-12-25 05:57:03
问题 Counting the number of records in a collection that is matched by a query even on an indexed field takes too much time. For example lets say there is a collection consists of 10000 records, and there is an index on the creationDate field of this collection. Getting the last ten records from the collection is faster than counting the number of records created on the last day. It takes more than 5 seconds, sometimes even up to 70 seconds to return the result of the count query. Do you have any

MongoDB HostName/URI Configuration

拥有回忆 提交于 2019-12-23 20:54:09
问题 Note this looks long, but provides context and lists my main questions at the bottom. I researched all parts and included references. I used the Google Cloud Launcher to create a Mongo database. This created a replica set of two Mongo servers (primary and secondary) and an arbiter on three separate VMs. I have not changed any VM configurations (other than opening the firewall). I have SSH'd into both of the servers and verified Mongo is working with replication as expected. I'm changing the

How to execute full text search command in MongoDB with Java Driver ?

孤街醉人 提交于 2019-12-19 03:12:10
问题 Mongo and Java gurus. Our team decided to use full text search API, introduced recently in MongoDB. However, we found some difficulties executing the command using the Java MongoDB driver. here is my code I am using : public BasicDBObject find(String search) { BasicDBObject searchCommand = new BasicDBObject(); searchCommand.put("text", new BasicDBObject().append("search", search)); CommandResult commandResult = db.command(searchCommand); } This is what I get when I print System.out.println

how to check from a driver, if mongoDB server is running

白昼怎懂夜的黑 提交于 2019-12-18 03:56:32
问题 I wonder, if there is a way to check if mongoDB server is running from java driver for mongoDB? According to the tutorial, I can do Mongo m = new Mongo(); // or Mongo m = new Mongo( "localhost" , 27017 ); // and DB db = m.getDB( "mydb" ); But how to check that I can use these Mongo and DB? I see no isConnected() method in the API. db.getConnector().isOpen() returns true The only way I found is call db.getDatabaseNames() and catch MongoException. If there some more civilized approach? 回答1: if

how to check from a driver, if mongoDB server is running

我与影子孤独终老i 提交于 2019-12-18 03:56:26
问题 I wonder, if there is a way to check if mongoDB server is running from java driver for mongoDB? According to the tutorial, I can do Mongo m = new Mongo(); // or Mongo m = new Mongo( "localhost" , 27017 ); // and DB db = m.getDB( "mydb" ); But how to check that I can use these Mongo and DB? I see no isConnected() method in the API. db.getConnector().isOpen() returns true The only way I found is call db.getDatabaseNames() and catch MongoException. If there some more civilized approach? 回答1: if

GeneratePDF with JasperReports Library and MongoDB

馋奶兔 提交于 2019-12-17 16:53:45
问题 Here is my GeneratePdf.java Import ... public class GeneratePdf { public static void main(String[] args) { try { JRDataSource ds = getDatasource(); // - Chargement et compilation du rapport line32 JasperDesign jasperDesign = JRXmlLoader.load("/home/gocoffee.jrxml"); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); // - Paramètres à envoyer au rapport Map parameters = new HashMap(); parameters.put("Titre", "Titre"); // - Execution du rapport JasperPrint jasperPrint

In MongoDB, how do I search in an array of sub-documents?

邮差的信 提交于 2019-12-13 02:16:12
问题 I have a survey document in mongodb, each survey have surveyRefId for unique identification. I am not able to understand how to find sub-documents having questionType = hard in documents whose surveyRefid = 377 or 360 . Here is a sample document: { "json": { "surveyRefId": 377, "surveyName": "survey on sociology", "questionsVoList": [ { "questionId": "556708425215763c64b8af3d", "questionText": "question no 1", "questionTitle": "", "questionType": "hard", "preQuestion": true, "questionOptions"

MongoDB list available databases in java

久未见 提交于 2019-12-12 10:43:16
问题 I am writing an algorithm that will go thru all available Mongo databases in java. On the windows shell I just do show dbs How can I do that in java and get back a list of all the available databases? 回答1: You would do this like so: MongoClient mongoClient = new MongoClient(); List<String> dbs = mongoClient.getDatabaseNames(); That will simply give you a list of all of the database names available. You can see the documentation here. Update: As @CydrickT mentioned below, getDatabaseNames is