Posts

Showing posts with the label mongodb

How to match the two strings with and without including spaces

For example: In DB I've the string value like "cell phones". If I get the string value like "cellphones" from frontend. How can I compare it with DB string and get the related string values in response. Just remove those spaces from the response you are getting after query find then pass the response to require input field. Then match that string with front-end or input string. If both matches load the required content. Suppose the collection name is Category. Then the sample query will be like this Category.find().exec((err, categories) => { var details=[] var matchCategory=[] categories.map((category,key)=>{ var obj ={} obj.name = category.name.toLowerCase().replace(/\s/g, "") details.push(obj); }) if(details.length > 0){ var detailsLength=details.length details.map((category,key)=>{ if(category.name=="cellphones"){ //...

MongoDB Java API slow reading peformance

We are reading from a local MongoDB all documents from a collections and performance is not very brillant. We need to dump all the data, don't be concerned why, just trust it's really needed and there is no workaround possible. We've 4mio documents that look like : { "_id":"4d094f58c96767d7a0099d49", "exchange":"NASDAQ", "stock_symbol":"AACC", "date":"2008-03-07", "open":8.4, "high":8.75, "low":8.08, "close":8.55, "volume":275800, "adj close":8.55 } And we're using this for now trivial code to read: MongoClient mongoClient = MongoClients.create(); MongoDatabase database = mongoClient.getDatabase("localhost"); MongoCollection<Document> collection = database.getCollection("test"); MutableInt count = new MutableInt(); long start = System.currentTimeMillis(); collection.f...