mongodb-java

How to store HTML data in MongoDB?

人盡茶涼 提交于 2019-12-13 12:31:45
问题 I'm trying to crawl the web and store HTML data on MongoDB using Java. Unfortunetely while storing data, MongoDB drivers nulling the data and stores empty field for HTML data. When I get the first 500 chars of HTML data, I can store/upsert it without a problem so I think something in HTML (or Javascript in it) corrupts the command sent to MongoDB and MongoDB stores empty data instead of HTML. ( EDIT : Also I've tried with 40.000 and 50.000 chars and 40.000 was OK but 50.000 char data didn't

Spring throws ConverterNotFound for range search on date in MongoDB

馋奶兔 提交于 2019-12-13 07:45:31
问题 I'm trying to do a range search on DateTime data format. The dates are being stored in Joda's DateTime format in the MongoDB. When I do a FIND query for a data greater than a given date, the ConverterNotFoundException is being thrown. Could someone please share information on why the conversation of Date object is being done to DateTime (Joda) &how can I possibly resolve this? Exception org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from

how to find document with mongoDB using mongodb java in sub array of document?

廉价感情. 提交于 2019-12-13 04:49:32
问题 This is really hard. I want to find the select nodes.index where radio.mac_address="00:06:5A:03:2E:5B" . how can I get this query in MongoDB using java? My mongodb is as following. I tried so many queries. one of them is as following BasicDBObject query = new BasicDBObject("nodes.radios.mac_address", "mac_address value"; BasicDBObject fields = new BasicDBObject("nodes.$", 1); DBCursor cursor = node_info.find(query, fields); Updated First on got solved How can i also write update query like

Setup custom converters in Spring Data Mongo

风格不统一 提交于 2019-12-12 19:12:46
问题 We are trying to setup our own Converters for Spring Data Mongo and having problems with it. Seems like Spring never calls for registerConvertersIn on CustomConversions and thus our custom converters added through overriden AbstractMongoConfiguration#customConversions never become part of conversion. We are using Spring Data Mongo 1.6.3, but it seems it could be a problem for 1.8.0 too (I've checked calls to CustomConversions#registerConvertersIn and found none.) I was able to fix this

DB.eval() with Mongo Java Driver

非 Y 不嫁゛ 提交于 2019-12-12 17:09:37
问题 I've prepared some script to execute on Mongo. It works as expected from command line: mongo 127.0.0.1:27017/dbName script.js But when I tried to move it in java (scala) code it doesn't work with db.eval(scriptContent) Does anybody succeed with DB.eval() method? 回答1: Question #1 : Why does it need to be in Java? Can you just schedule the mongo ... command above to run via cron? Question #2 : Is it possible to implement via the Java driver instead? The Java driver can execute Map / Reduce

How to deserialize json document obtained from mongoDB into a POJO?… (Migrating from Morphia to Java Mongo Driver 3.0)

笑着哭i 提交于 2019-12-12 13:29:06
问题 BACKGROUND Initially, Morphia was being used to interact with a mongo database. This was fine and worked nicely, but there was one caveat... Some mapping exception was being spilled and clogging the logs. See my Unresolved Question on that particular issue. <=== This didn't stop the application from functioning correctly. Morphia helped in getting the documents mapped to their corresponding entities ( basically POJOs ) and these were easily rendered to the Views. However, after much

Selective replication in mongodb

那年仲夏 提交于 2019-12-12 06:38:28
问题 I have two MongoDB running in two different servers connected via LAN. I want to replicate records from few collections from server 1 to collections in server 2. Is there any way to do it. Below is the pictorial representation of what I want to achieve. Following are the methods I consider using. MongoDB replication - But it replicates all collections. Is selective replication possible in MongoDB ?? Oplog watcher APIs - Please suggest some reliable java APIs Is there any other way to do this

How to read date (Timestamp) from MongoDB using Java

微笑、不失礼 提交于 2019-12-12 03:53:24
问题 Am trying to read date field from MongoDB in below format Formate: YYYY-MM-dd HH:mm:ss.SSSSSS 2017-01-23-10.46.07.812000 - DB2 2017-01-23T16:46:07.812Z - Stored in MongoDB (While viewing from GUI tool) Mon Jan 23 22:16:07 IST 2017 - Result/Reading from MongoDB // Formatter for the input date final DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy"); final ZonedDateTime dateFiledParsed = ZonedDateTime.parse(dateFiled.toString(), inputFormat); final

Get the count of Fields in each document through query using MongoDB java driver

时光毁灭记忆、已成空白 提交于 2019-12-12 03:25:08
问题 Is it possible to get the number of fields in document using a Query From MongoDB java Driver Example: Document1 :{_id:1,"type1": 10 "type2":30,"ABC":123,"DEF":345} Document2 :{_id:2,"type2":30,"ABC":123,"DEF":345} Note: In second document "type1" key doesnt exist . When i project Is it possible to project only "type1" and "type2" and get number of fields existing in that document. With current code i am getting all the documents and individually searching if there is the key i am looking is

Authentication on MongoDB 3.0.5 with Java Driver 3.0.3 and GridFS

元气小坏坏 提交于 2019-12-12 03:18:37
问题 I am trying to connect from Java Driver 3.0.3 with the connection string below to a Mongo 3.0.5: mongodb://admin:pass@myIP:myPort/databasename?authSource=databasename but I am getting the following exception: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches PrimaryServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=myIP:myPort, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoException: java.lang