mongodb-java

Converting the date returned from mongo to this format 2015-10-25

送分小仙女□ 提交于 2019-12-12 02:55:28
问题 I have a json file returned from mongo db as follow: [ { "_id": { "$date": "2014-10-19T04:00:00.000Z" }, "value": 29 }, { "_id": { "$date": "2014-10-20T04:00:00.000Z" }, "value": 20 }, { "_id": { "$date": "2014-10-21T04:00:00.000Z" }, "value": 21 } ] Now I want to read the date in java in the following format: 2014/10/25 but when I use: System.out.println("DAte is : "+result.get("_id").toString() ); the result is : DAte is : Sun Oct 19 01:00:00 ADT 2014 Then only thing that comes to my mind

MongoDB Aggregation command to Java code

让人想犯罪 __ 提交于 2019-12-12 02:42:36
问题 This is my mongodb shell command: db.dais_employee.aggregate([ { "$redact": { "$cond": { "if": { "$gt": [ { "$subtract": [ "$modifiedon", "$createdon" ] }, 1000 * 60 * 60 * 24 ] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ]) which works fine. I need to work this MongoDB command in java and I need help for using MongoDB Aggregation framework with java driver. When I am trying to run this command using java driver: AggregateIterable<Document> iterable = collection.aggregate(asList( new

How to make MongoCollectoin return java.sql.Timestamp?

半城伤御伤魂 提交于 2019-12-12 02:19:36
问题 Basing on https://jira.mongodb.org/browse/JAVA-1741 I'm trying to implement and use TimestampCodec, and expect that decode() is used when reading MongoCollection, but for some reason decode() is not executed and so IsoDate value from database is converted to java.util.Date instead of expected java.sql.Timestamp. What is the right way to make my TimestampCodec.decode() be used when retrieving MongoCollection? I have the following, but it fails with java.lang.AssertionError: expected:<class

MongoDB Java Client stores “_id” as null on “replaceOne”

荒凉一梦 提交于 2019-12-12 01:25:27
问题 We have upgraded (from 2.11.1) to <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.4.1</version> Now when we do this: UpdateOptions options = (new UpdateOptions()).upsert(true); BasicDBObject queryObject = new BasicDBObject("_id", newObject.get("_id")); //where newObject.get("_id") returns "null", i.e. same as //BasicDBObject queryObject = new BasicDBObject("_id", null); UpdateResult result = collection.replaceOne(queryObject, newObject, options); will

is procedure exist in mongodb

白昼怎懂夜的黑 提交于 2019-12-11 18:22:17
问题 I am newbie to mongodb (java). I need to execute list of commands(queries in relational) by using something similar to procedures in relational db. Is it possible in mongodb? 回答1: MongoDB has no real sense of stored procedures. It has server side functions however these functions: Do not work with sharding Are slow Must be evaled (Dr. Evil) Are only really designed to be used within Map Reduces to stop you from having to house mutiple copies of common code within many places. However you can

MongoDB Aggregration Framework and Java Driver making $or condtion work

允我心安 提交于 2019-12-11 14:19:39
问题 I am working on a method that queries a mongoDB using the aggregator framework. I have built up the aggregate but I keep getting the following exception: Pipeline::run(): unrecognized pipeline op \"$or" If I understand correctly when you append or add DBObjects to the query they are implicitly added as and operations. I may be really tired right now but I can't think of a way to or two conditions with the aggregation framework. The following is a snippet of my code: DBObject

spring data mongodb “id” field mapping

情到浓时终转凉″ 提交于 2019-12-11 11:29:33
问题 I have a document with an array field with "chapters": [ { "id" : "14031871223912313", ...} ... ] I would like to query return the id's with Spring Data's MongoTemplate using the following: class Chapter { private String id; public String getId() { return id; } } This way the id is not populated. I have tried using the different mapping options with @Field described here http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mapping.conventions.id-field What am I doing wrong?

Mongodb replacement for GROUP_CONCAT in mysql

一个人想着一个人 提交于 2019-12-11 09:19:32
问题 Dear All, We have started using mongodb for our internal project. I am facing some issues and need your help. Here is my table... books_issued user_id book_id 1 1 1 3 2 5 2 8 I want to list it using the $group and result should be like this... user_id book_id 1 1,3 2 5,8 We are using $match and $group. Please help to solve the same using java api. Thanks, Op 回答1: This query uses the user_id as _id field for the aggregate and adds the book_id to the books array: db.books_issued.aggregate( {

Mongodb find query

孤街浪徒 提交于 2019-12-11 08:47:19
问题 seasons.json { "_id" : "unique_1", "spring" : [{ "fruit" : "mango", "person_id" : [101.0, 102.0, 103.0, 104.0] }, { "fruit" : "banana", "person_id" : [151.0, 152.0, 153.0, 154.0] }], "summer" : [{ "fruit" : "mango", "person_id" : [201.0, 202.0, 203.0, 204.0] }, { "fruit" : "banana", "person_id" : [251.0, 252.0, 253.0, 254.0] }], "fall" : [{ "fruit" : "mango", "person_id" : [301.0, 302.0, 303.0, 304.0] }, { "fruit" : "banana", "person_id" : [351.0, 352.0, 353.0, 354.0] }], "winter" : [{ "fruit

NoSQL MongoDB vs Cassandra

孤街浪徒 提交于 2019-12-11 08:47:00
问题 I am developing a cloud platform and I want to Store documents and video files. First concept was to use MongoDB for the simple documents and for large video files cassandra. But i have read that with cassandra i'll have a problem if the file is larger than 64 MB. On the other hand mongoDB has GridFS that allows files larger than 100MB. I have connected mongoDB with Java. At start the database was 80MB, when I inserted a 1.80GB video file with GridFS into MongoDB i was expecting the Database