mongodb-java

Retrieve data from MongoDB collection into Swing JTable

↘锁芯ラ 提交于 2019-12-04 19:28:12
I am a newbie in database projects. I don't know how to display a collection in mongodb inside a swing window (EDIT: JTable) after connecting it to the database server....plz help me out in this... I have tried doing this in sql but am not able to do using mongodb JButton btnDisplay = new JButton("display"); btnDisplay.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // To connect to mongodb server MongoClient mongoClient = new MongoClient( "localhost" , 27017 ); // Now connect to your databases DB db = mongoClient.getDB( "test" ); System.out.println(

Creating a mongodb capped collection in java

萝らか妹 提交于 2019-12-04 13:43:37
问题 I want to create a capped collection from Java code. I found the syntax for creating it through JavaScript, but could not find an example for Java. Mongo mongo = new Mongo("127.0.0.1"); DB db = mongo.getDB("mydbid"); DBCollection collection; if (db.collectionExists("mycollection")) { collection = db.getCollection("mycollection"); } else { collection = /* ????? Create the collection ?????? */ } } 回答1: Use the DB.createCollection operation and then specify a DBObject that has capped as a

Closing MongoDB Java Connection

梦想与她 提交于 2019-12-04 07:20:57
I am trying to design a Mongo Db connection class where I am maintaning MongoClient as static. private static MongoClient client = null; public static DB connectToMongo() throws Exception { if (null != client) { return client.getDB(DBNAME); } client = new MongoClient(HOST,PORT); return client.getDB(DBNAME); } My whole web application uses the above method to connect to Mongo as follows: db = MongoDBConnection.connectToMongo(); collection = db.getCollection("collectionName"); After performing DB operations I never call the close connection for MongoClient. The connection class would always

MongoDB+Azure+Android: Error: com.mongodb.MongoException: not talking to master and retries used up

爷,独闯天下 提交于 2019-12-04 05:10:47
问题 Background : I have MongoDB replica sets running in Azure cloud service worker + web roles, using mongo-azure library. The first time I setup my Android project to connect to MongoDB/Azure, IO (reads and writes) worked. Then, I crashed the app because of a typo in my hardcoded test JSONString, so the Mongo instance wasn't able to properly close. After fixing that JSONString problem, I received the following error (in stack trace) and wasn't able to access MongoDB/Azure. Perhaps not closing

Persisting Objects containing Objects with spring-data-mongodb

雨燕双飞 提交于 2019-12-04 03:28:35
问题 Below is a follow-up question to Question 13832188: I'm using spring-data-mongodb version 1.1.1.RELEASE . I am able to persist an object if all the member variables are primitive types, even if the names of the @PersistenceConstructor arguments don't match exactly the names of the member variables by using the @Field and @Value annotations. However, I get a MappingInstantiationException when I try to persist objects that contain other objects. My questions: Is this a bug in spring-data

Why do I end up with java.lang.IllegalArgumentException for Casbah / Java MongoDB Driver?

谁说胖子不能爱 提交于 2019-12-03 22:02:47
I'm seeing a strange issue using the casbah / java driver. I keep running into the following exception when the driver tries to create a response from mongo: Oct 16, 2012 10:45:07 AM com.mongodb.DBTCPConnector$MyPort error SEVERE: MyPort.error called java.lang.IllegalArgumentException: response too long: 1634610484 at com.mongodb.Response.(Response.java:40) at com.mongodb.DBPort.go(DBPort.java:110) at com.mongodb.DBPort.go(DBPort.java:75) at com.mongodb.DBPort.call(DBPort.java:65) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201) at com.mongodb.DBApiLayer$MyCollection.__find

how to pivot data using spring-data-mongodb

十年热恋 提交于 2019-12-03 21:36:41
I have data of this form and I referred to this link pivoting in mongodb : Name, SumPrice, type,year A, 50.0, Retail,2015 B, 467.0, Online,2015 A, 1456.0, Direct,2015 B, 1149.53, Direct,2015 C, 273.20, Online,2014 C, 110.0, Direct,2014 I want data to be transformed using spring-data-mongodb of this form Name ,Retail, Online , Direct, year A, 50.0 , 0.0, 1456.0 2015 B, 0.0, 467.0, 1149.53, 2015 C, 0.0, 273.20, 110.0, 2014 Please lemme know how to do. Regards kris 来源: https://stackoverflow.com/questions/32902502/how-to-pivot-data-using-spring-data-mongodb

mongodb java driver query with regexp number fields

为君一笑 提交于 2019-12-03 21:00:43
I'm trying to convert this query in java: db.beni.find({ $where: function() { return /.*11/.test(this.foglio) || /.*99/.test(this.comune) } }) Where this.foglio is a numeric field and this.comune is a string fields. Thanks 来源: https://stackoverflow.com/questions/9824339/mongodb-java-driver-query-with-regexp-number-fields

Converting DBObject to Java Object while retrieve values from MongoDB

假装没事ソ 提交于 2019-12-03 13:46:47
From my Java application, I have stored the values in mongoDB in ArrayList(set of Java objects). How can I retrieve the data from DBObject I am storing the data in mongoDB like this: { "students" : [{"firstName" : "Jesse", "lastName" : "Varnell", "age" : "15", "gender" : "M" }, { "firstName" : "John", "lastName" : "Doe", "age" : "13", "gender" : "F"}] } I am having the Java Object for the Student like: public class Student { public String firstName; public String lastName; public String age; public String gender; // M, F } I am retrieving the data from mongoDB like: BasicDBObject query = new

Mongo DB query in java

女生的网名这么多〃 提交于 2019-12-03 11:16:50
I have to write a complex mongo query using java but am not able to do it. The mongo query looks like this: db.video.findOne( { $or: [ { key1: { $in : [764] } }, { key2: {$in : [list2] } }, { $and [ { key2 : 3}, {key4:67} ] } ] }) I have to write the above query using the QueryBuilder class. In what way can I do it? Thanks Using QueryBuilder your query should look like this DBObject query = QueryBuilder.start().or( QueryBuilder.start("key1").in(764).get(), QueryBuilder.start("key2").in(keys).get(), QueryBuilder.start().and("key3").is(3).and("key4").is(64).get() ).get(); Consider using jongo