mongodb-java

subtraction in mongo query does not work?

丶灬走出姿态 提交于 2019-12-06 22:36:27
I have a collection as follow: { "_id" : ObjectId("5491d65bf315c2726a19ffe0"), "tweetID" : NumberLong(535063274220687360), "tweetText" : "19 RT Toronto @SunNewsNetwork: WATCH: When it comes to taxes, regulations, and economic freedom, is Canada more \"American\" than America? http://t.co/D?", "retweetCount" : 1, "source" : "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>", "Date" : ISODate("2014-11-19T04:00:00.000Z"), "Added" : ISODate("2014-11-19T04:00:00.000Z"), "tweetLat" : 0, "tweetLon" : 0, "url" : "http://t.co/DH0xj0YBwD ", "sentiment" : 18, "quality" : 0.4,

how to call count operation after find with mongodb java driver

让人想犯罪 __ 提交于 2019-12-06 17:32:09
问题 I am using MongoDB 3.0. suppose there is a set of documents named photos , its structure is {"_id" : 1, photographer: "jack"} with database.getCollection("photos") , Mongodb will return a MongoCollection object, on which I have the method count() to get the number documents returned. However, when I make queries with specific conditions. For example find documents with id smaller than 100 : photosCollections.find(Document.parse("{_id : {$lt : 100}}")) Above find method will always return a

Retrieve data from MongoDB collection into Swing JTable

爷,独闯天下 提交于 2019-12-06 12:18:57
问题 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(

Restrict fields in Result

放肆的年华 提交于 2019-12-06 05:29:59
I am working with MongoDB v3.0.1 and the MongoDB Java Driver 3.0.0-RC1. I have an user collection with fields like "username", "firstname", "lastname", "email", and so on. Now I want to select all users but only with the fields "username", "firstname" and "lastname". On the Mongo-Shell it is working with db.user.find({}, { "username" : true , "firstname" : true , "lastname" : true}) But how can I do it in Java? I tried it with final BasicDBObject query = new BasicDBObject("{}", new BasicDBObject("_id", true)); final MongoCursor<Document> usersCursor = col.find(query) For this I get an empty

How to write multiple group by id fields in Mongodb java driver

时光毁灭记忆、已成空白 提交于 2019-12-05 11:41:01
In the below query { $group : { _id : { success:'$success', responseCode:'$responseCode', label:'$label'}, max_timeStamp : { $timeStamp : 1 }, count_responseCode : { $sum : 1 }, avg_value : { $sum : "$value" }, count_success : { $sum : 1 } }} How _id : { success:'$success', responseCode:'$responseCode', label:'$label'}, can be translated to use in java mongodb driver. I tried BasicDBList list = new BasicDBList(); list.add(new BasicDBObject("success", "$success")); list.add(new BasicDBObject("responseCode", "$responseCode")); list.add(new BasicDBObject("label", "$label")); AggregationOutput

MongoDB full text search index: error: too many text index for, why?

不想你离开。 提交于 2019-12-05 07:55:36
I have one problem, I have collection and I want to set text search index to 2 fields(description and title). But when I add second index I get following error and text search stopped working. { "serverUsed" : "localhost/127.0.0.1:27017" , "ok" : 0.0 , "errmsg" : "too many text index for: testdb.users"} when I delete one index search start work again. what is the problem? One collections support full text search index only for one field???? I am using the current version of mongodb under windows and I am using mongodb java driver API. Thanks MongoDB only allows one text-index per collection.

mongodb java driver query with regexp number fields

我的梦境 提交于 2019-12-05 05:36:01
问题 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

how to call count operation after find with mongodb java driver

ⅰ亾dé卋堺 提交于 2019-12-04 23:07:38
I am using MongoDB 3.0. suppose there is a set of documents named photos , its structure is {"_id" : 1, photographer: "jack"} with database.getCollection("photos") , Mongodb will return a MongoCollection object, on which I have the method count() to get the number documents returned. However, when I make queries with specific conditions. For example find documents with id smaller than 100 : photosCollections.find(Document.parse("{_id : {$lt : 100}}")) Above find method will always return a cursor which doesn't provide a count() function. So how can I know how many documents returned ? I know

Can't find MongoClient in Java Drivers

时光毁灭记忆、已成空白 提交于 2019-12-04 23:02:21
In reading all the documentation on the mongo site for using the Java Driver, it makes references to using MongoClient() to make a connection. It talks about how they formerly used Mongo() but it has been deprecated. However, when I download the latest (or any) version of the java driver that the Mongo database links to ( http://central.maven.org/maven2/org/mongodb/mongo-java-driver/ ), and load it into my project libraries, I cannot import com.mongodb.MongoClient because it isn't there! I've tried half a dozen different versions of the driver they link to. I can actually make my program work

mongoDB selecting record based on two conditions

℡╲_俬逩灬. 提交于 2019-12-04 19:45:37
A sample record in my database looks like : { "_id" : 2, "name" : "Corliss Zuk", "scores" : [ { "type" : "exam", "score" : 87.53859552156015 }, { "type" : "quiz", "score" : 24.49132971110967 }, { "type" : "homework", "score" : 99.24881912510654 } ] } I am trying to select all records that have homework scores > 90 or exam scores < 50. My OR condition is like this: DBObject clause1 = new BasicDBObject("scores.type", "homework").append("scores.score", new BasicDBObject("$gt", 90)); DBObject clause2 = new BasicDBObject("scores.type", "exam").append("scores.score", new BasicDBObject("$lt", 50));