mongodb-java

MongoDB - Storing date without timezone

末鹿安然 提交于 2019-12-31 01:27:28
问题 We have a simple application in which we have all user in same timezone & therefore we are not interested to store timezone information in mongo date object. Reason for such extreme step is we have multiple micro service using common database managed by different developers. Each of them requires to explicitly set timezone related stuff in query & forgetting same results in invalid dataset. Since currently MongoDB folks Mongo Data Types doesn't support storing dates without timezone. Just

Getting MongoDB error on Write - quota exceeded

孤街浪徒 提交于 2019-12-30 11:02:44
问题 I have a JAVA app which writes to a replicaset. Am using 3.0.7 version of MongoDB server. The mongo-driver for Java is 3.0.4. It was working just fine but now am getting the following error on ALL writes: com.mongodb.MongoWriteException: quota exceeded at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:487) at com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:474) at com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:325) Have

Getting MongoDB error on Write - quota exceeded

泄露秘密 提交于 2019-12-30 11:02:14
问题 I have a JAVA app which writes to a replicaset. Am using 3.0.7 version of MongoDB server. The mongo-driver for Java is 3.0.4. It was working just fine but now am getting the following error on ALL writes: com.mongodb.MongoWriteException: quota exceeded at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:487) at com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:474) at com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:325) Have

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

Append data to existing gridfs file

ⅰ亾dé卋堺 提交于 2019-12-29 08:07:12
问题 As i can see java mongo driver does not provide capability to get OutputStream from existing gridFS file com.mongodb.gridfs.GridFSFile I have to create GridFSInputFile directly or use gridFs.createFile() method. Is it a lack of java driver or a restriction of gridfs ? Could you suggest any workaround except create new file/delete old one ? Thank you 回答1: GridFS is not a core feature of MongoDB but a convention of storing binary data with accompanying metadata. You should be able to modify any

Persisting objects containing primitive arrays with spring-data-mongodb

試著忘記壹切 提交于 2019-12-25 10:18:23
问题 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("foo") and @Value("#root.foo") annotations. However, I get a MappingInstantiationException (Illegal arguments for constructor) when I try to persist objects that contain primitive arrays. This holds true regardless of whether the

MongoDB java client's WriteConcern doesn't work

99封情书 提交于 2019-12-25 07:01:45
问题 I am a newbie to use MongoDB. I just imported the latest MongoDB java client via Maven: <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.2.2</version> </dependency> And then I wrote a very simple program to test the insert operation. //I use a replicaset MongoClient mongoClient = new MongoClient( Arrays.asList(new ServerAddress("10.12.16.136", 29017), new ServerAddress("10.12.16.136", 29018), new ServerAddress("10.12.16.136", 29019))); //I just

Querying Mongo Collection using QueryBuilder in Mongo 3.3.0

南笙酒味 提交于 2019-12-25 04:51:13
问题 Our code with mongo-java-driver 3.0.4 used to be like - DBCollection dbCollection = mongoClient.getDB(databaseName).getCollection(collectionName); QueryBuilder queryBuilder = new QueryBuilder(); /** queryBuilder.put() for building the query */ DBCursor dbCursor = dbCollection.find(queryBuilder.get()); while(dbCursor.hasNext()) { DBObject dbObject = dbCursor.next(); // add entries to a list of TDocument type } Converting this to the mongo-java-driver 3.3.0, I ended up with this -

Querying Mongo Collection using QueryBuilder in Mongo 3.3.0

吃可爱长大的小学妹 提交于 2019-12-25 04:50:07
问题 Our code with mongo-java-driver 3.0.4 used to be like - DBCollection dbCollection = mongoClient.getDB(databaseName).getCollection(collectionName); QueryBuilder queryBuilder = new QueryBuilder(); /** queryBuilder.put() for building the query */ DBCursor dbCursor = dbCollection.find(queryBuilder.get()); while(dbCursor.hasNext()) { DBObject dbObject = dbCursor.next(); // add entries to a list of TDocument type } Converting this to the mongo-java-driver 3.3.0, I ended up with this -

How to get array of document using Mongodb java?

左心房为你撑大大i 提交于 2019-12-25 02:57:24
问题 How to get all the document under array in mongodb java. My Database is as below. Want to retrieve all the data under array 198_168_1_134 . below is some of What i tried, eventlist.find(new BasicDBObject("$match","192_168_10_17")) eventlist.find(new BasicDBObject("$elemMatch","192_168_10_17")) eventlist.find(null, new BasicDBObject("$192_168_10_17", 1)) 回答1: You have two options: using .find() with cherry-picking which document you have to have fetched. using the aggregation framework by