w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
MongoDB full text search with haskell driver
The text-command can be written in another structure: { text: your_collection , search: your_text , filter: your_filter , limit: your_limit , project: your_projection } I had my suspicion, since all "runCommand"-action have the same structure. So I tried to apply that structure to the text-command - but without success. Then I remembered that aggregate has another structure too and tried that, but that didn't work either. Finally, I found the answer in a google group entry of the Java driver.

Categories : Mongodb

How to Update a Document in MongoDB w/Java Driver
I think your problem is here: criteriaObject.append( "_id", "ObjectId("520a56b730047339c26ec1fa")"); Should be: criteriaObject.append( "_id", new ObjectId("520a56b730047339c26ec1fa"); That way the field value is treated as an object id, not as string (containing the literal "ObjectId")

Categories : Java

how to design full text search algorithm where keyword quantity is huge (like Google Alerts)?
I can think of the following: (1) Make sure each search query is really fast. Millisecond performance is very important. (2) Group multiple queries with the same keywords and do a single query for each group. Since different queries are using different keywords and AND/OR operations, I don't see other ways to group them.

Categories : Regex

Can't select full long text document in mongoDB
This was a bug (SERVER-6646) in MongoDB shell and fixed in 2.4.5. NUL will now show up in the shell as "u0000", along with the rest of string

Categories : Mongodb

How do upload text document and is it possible to enable full text search on it?
I haven't ever done most of the things in your requirements, but I work quite heavily with a text parser that converts MS Word documents into XML documents. Perhaps I can at least get you started in the right direction for that. We use a Java library called POI, by Apache that makes the DOC -> XML conversion a simple process. Since you're using JRuby, I'd imagine it'll be much easier for you to integrate it into your project since we're using MRI Ruby. That was a PITA because we had to include lots of bridges and other junk just to be able to use the .jar files. Personally, I've used the Carrierwave gem to handle file uploading. It's a snap to upload files & attach them to models. You simply use the Carrierwave generator to generate an Uploader class that attaches to a field in a mod

Categories : Ruby

MongoDB full text search in production?
Currently (September 2013) The MongoDB fulltext search is still in beta stage. The documentation explicitely warns from using it: The text search is currently a beta feature [...] Warning: •Do not enable or use text search on production systems. Likely reasons for this warning: Implementation- and API details are subject to change. Anything you develop and which works now could fail the next time you update MongoDB. It isn't fully tested. There could still be obscure bugs lurking in it which could break your application. For these reasons you should not use it in a real-world application before 10gen has declared it finished. Update: As of Version 2.6, text search has production quality.

Categories : Mongodb

Mongodb full text search matching precesion
Currently, MongoDB's text search does not support searching on partial words. The command matches on the complete stemmed word-- it's likely that 'bluetooth' and 'bluetoot' stem to the same root which is why that search term is working while 'blue' is not. (Source.) MongoDB's text search uses the open source stemmer Snowball. If you're still interested in implementing autocompletion, using regexp or an outside autocomplete library (perhaps Typeahead.js?) is probably your best bet. For example, if you wanted to suggest article titles, you could cache the titles to a json file every few days and pass that json data to Typeahead.js.

Categories : Mongodb

how to do full text search on mongodb array fields?
The second parameter on ensureIndex function is options. You should create an unique index on both fields: db.metadatanew.ensureIndex( { "Keywords" : "text", "Filename" : "text"} ) See more: http://docs.mongodb.org/manual/tutorial/create-text-index-on-multiple-fields/

Categories : Java

Implementing MongoDB 2.4's full text search in a Meteor app
To create a text index and try to add like this I hope so it will be useful if there is still problem comment From docs.mongodb.org: Append scalar index fields to a text index, as in the following example which specifies an ascending index key on username: db.collection.ensureIndex( { comments: "text", username: 1 } ) Warning You cannot include multi-key index field or geospatial index field. Use the project option in the text to return only the fields in the index, as in the following: db.quotes.runCommand( "text", { search: "tomorrow", project: { username: 1, _id: 0 } }

Categories : Javascript

mongodb full text search and json objects
According to the documentation ( http://docs.mongodb.org/manual/core/text-search/ ) the text index should be on the field or fields whose value is a string or an array of string elements. So as you pointed out, the json field will not work.

Categories : Mongodb

mongodb full text search: phrases with special character "-"
The - means that it's a negated search, but that shouldn't happen in phrase searches (enclosed by "). I would suggest you file a bug report at http://jira.mongodb.org as this seems a bug.

Categories : Mongodb

MongoDB query for full text search and Geo returning wrong result
According to the 2.4 documentation, text indexes do not work with $near: Note You cannot combine the text command, which requires a special text index, with a query operator that requires a different type of special index. For example you cannot combine text with the $near operator.

Categories : Mongodb

MongoDB C# driver upserting nested document
Try with $addToSet The $addToSet operator adds a value to an array only if the value is not in the array already. If the value is in the array, $addToSet returns without modifying the array. Something else you can do is to load your CoreElement and work with it in memory. You can add Suffs and MoreStuffs to the object checking for duplicates with C#. When you are finished with the object just save it, MongoDB will replace the object in the collection with your modified object.

Categories : Mongodb

Full-text-search in a xml file with java (with Xpath?)
You can write a simple SAX parser to process your XML. Here's the Oracle SAX tutorial for starting. You can go through all nodes, mark (and save) those nodes that are interesting for you, and return the resulting nodes as a new XML document, or String, or whatever form you want.

Categories : Java

MongoDB Java Driver: How to insert into any collection from Java Driver
Sample: DBCollection coll = db.getCollection("collection"); /* { "name" : "MongoDB", "type" : "database", "count" : 1, "info" : { x : 203, y : 102 } } */ BasicDBObject doc = new BasicDBObject("name", "MongoDB"). append("type", "database"). append("count", 1). append("info", new BasicDBObject("x", 203).append("y", 102)); coll.insert(doc);

Categories : Java

MongoDB driver ruby, remove field in document
Your syntax looks slightly incorrect. As per docs: collection.update( { _id: @id }, { $unset: { herField: true } }, { multi: true }); Need the 'multi' option if you want to update multiple documents. E.g. from all records on this collection. http://docs.mongodb.org/manual/reference/operator/unset/#op._S_unset

Categories : Ruby

FULL TEXT INDEX - Huge Performance Decrease on Multiple Tables
Your question comments suggest you improved performance to a satisfactory level by rewriting an unrelated part of the query (not shown in the question). This is fair enough if it works, but doesn't explain why the two separate queries and the combined query differ so significantly, when other unrelated parts of the query are kept constant. It's difficult to say confidently without seeing a query plan and statistics results; however I can think of two possibilities based solely on reasoning about how the SQL queries are written: One or both of the ID columns (from FooBar and FooBalls) may be non-unique in the row set after these two tables have been inner joined. Doing two, rather than one, join to CONTAINSTABLE result sets may thus be "breeding" rather more records than a single join

Categories : Sql Server

search for multiple values, sort by relevance (php + MySQL, no full text search)
You can do the count in SQL. Here is an example: select ((col like 'term1') + (col like 'term2') + . . . (col like 'termN') ) as NumMatches from t having NumMatches > 0 order by NumMatches desc; MySQL treats booleans as 0 (for false) and 1 (for true). You can add them together to get the total number of matches.

Categories : PHP

Google Analytics Custom Site Search (Lucene / Sql Server Full Text Search)
How frequently do visitors use my search box and what are they looking for? You can have this metric using Google Analytics Site Search Feature Are visitors satisfied with what they find? Not sure about this but this can be very well derived from the metrics like bounce-rate/exit-rate What are most popular keywords? This is also available in Google Analytics How much time it takes to return results based on the Search "Keyword" The page load time of the search result page would provide you an approximate estimate of this metric Do users actually use Search Results? In google analytics you get the number of visits which used search Google Analytic Site Search Feature works with your website and not with Google Search Engine You might want to read more about

Categories : Google Analytics

installing MongoDB java driver
First, that is not the correct jar. The jar you are referencing above contains the javadocs. The driver jar is: mongo-java-driver-2.9.3.jar. Secondly, you need to add the jar to your project's classpath in order to use it. These are not executable jars. Take a look at the getting started docs here: http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/#getting-started-with-java-driver There is no "installing" the driver. You just add it as a dependency in your project and you use it in your code. You do have to install the database itself. The installation packages for the database are available here: http://www.mongodb.org/downloads

Categories : Java

MongoDB WriteConcern Java Driver
Subtle but simple problem. I was using a def to create my connection... which I then proceeded to call twice as if it was a val. So I actually had 2 different writers so that explained the sometimes-difference in my results. Refactored to a val and all was predictable. Agonizing to identify, easy to understand/fix.

Categories : Mongodb

How to upsert with mongodb-java-driver
You cannot set _id if dbobject is just a document and does not contain an update operator eg: $set, $setOnInsert. Just passing a document will replace the whole document meaning it doesn't set an _id a falls back to ObjectId So your example works if you use an update operator eg: db.getCollection(collection).update( new BasicDBObject("_id", "12"), new BasicDBObject("$set", new BasicDBObject("Hi", "world")), true, false)

Categories : Java

MongoDB - Java Driver performance
Default Write concern has changed from NORMAL to SAFE for Java driver since V 2.10.0 See here This means that in the older driver version insert operations by default return as soon as a message is written to socket. In the newer driver version on the other hand, operations by default must be acknowledged by the server before returning, which is much slower.

Categories : Java

When does MongoDB Java Driver makes connection?
1) connection is established when we do some operation ( find, update, remove, etc ) 2) Doc says : "Typically you create only 1 instance for a given database cluster and use it across your application". So, there is no point of caching DB object, and it is also not cached in driver code 3) DBCollection and DB are thread-safe. DBCollection are cached in DBApiLayer class in the driver.

Categories : Java

MongoDB Java driver - Object types
Why not get the object and call getClass() on it? myBSON.get("myKey").getClass() Seems like that is just as easy as calling some myBSON.getTypeOf("myKey") method that does not exist and would also be redundant in the API.

Categories : Java

MongoDB Java driver: distinct with sort
MongoDB doesn't support server-side sorting with the distinct command. What's happening in the console is that the distinct('myKey') call returns an array and then you're calling the JavaScript sort method on that array which returns a sorted version of the array. The parameters you pass into sort are ignored. To do the equivalent in Java you would do: List myKeys = myCollection.distinct("myKey"); java.util.Collections.sort(myKeys); To get the unique keys using a server-side sort you could use aggregate. Here's how you'd do that in the shell: db.mycollection.aggregate([ { $group: {_id: '$myKey' }}, { $sort: {_id: 1}} ]) However, when I tested this, the simple client-side sort approach performed much better.

Categories : Java

Windows search - full text search in c#
Here is the code that does work - in example I made it to search for the word "dummy" in the desktop folder: string connectionString = "Provider=Search.CollatorDSO;Extended Properties="Application=Windows""; OleDbConnection connection = new OleDbConnection(connectionString); string query = @"SELECT System.ItemName FROM SystemIndex " + @"WHERE scope ='file:" + System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "' and FREETEXT('dummy')"; OleDbCommand command = new OleDbCommand(query, connection); connection.Open(); List<string> result = new List<string>(); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { result.Add(reader.GetString(0)); } connection.Close();

Categories : C#

Updating mongodb with java driver takes forever?
That's because you are taking extra steps to update. You don't need to parse JSONs manually and you don't have to do the query-then-update when you can just do an update with a "where" clause in a single step. Something like this: BasicDBObject query= new BasicDBObject().append("organizationNumber",id); Unit unit = new Unit(fields); BasicDBObject unitDB= new BasicDBObject().append("someField",unit.getSomeField()).append("otherField",unit.getOtherField()); collection.update(query,unitDB); Where query specifies the "where" clause and unitDB specifies the fields that need to be updated.

Categories : Java

What does "response too long" means in MongoDB Java driver?
As the error description says, it is caused by a server which took too long to respond to the request. Possibly this is caused by firewall settings in your server. Try to check if the server can write response out through the port you are using for your MongoDB.

Categories : Java

MongoDB Java driver: Undefined values are not shown
Currently undefined is not supported by the java driver as there is no equivalent mapping in java. Other drivers such as pymongo and the js shell handles this differently by casting undefined to None when representing the data, however it is a separate datatype and is deprecated in the bson spec. If you need it in the java driver then you will have to code your own decoder factory and then set it like so: collection.setDBDecoderFactory(MyDecoder.FACTORY); A minimal example that has defined handling for undefined and factory is available on github in the horn of mongo repo.

Categories : Java

not able to insert documents into collection using mongodb java driver
The 'n' value from the getlasterror of an insert is always zero. (The 'n' value is what the WriteResult.getN() returns.) See this MongoDB Jira ticket: https://jira.mongodb.org/browse/SERVER-4381. Which has been closed in preference to a new insert, update, remove mechanism: https://jira.mongodb.org/browse/SERVER-9038 Long story short. You are not mad or missing anything. It is a "feature" of MongoDB that will hopefully finally be fixed with the 2.6 release. Rob. Edit: I modified your example slightly to print the saved document. Can you try running this version in your environment? import java.net.UnknownHostException; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBObject; import com.mongodb.MongoClient; import com

Categories : Java

mongodb java driver not finding master after rs.stepDown()
No one ever answered this so I decided that the recovery from replica sets was non-functional. Instead I went to sharding and hoped that layering a mongos between the app server and the clusters themselves would provide enough protection. The answer was a definitive "sort of". Before, when I stepped a primary down (or simulated a crash) the app server would hang indefinitely. Now I just get a few errors about not finding a primary in a given cluster and then the system recovers. Not a desirable solution but at least it is better than a permanent failure.

Categories : Mongodb

querying array of objects using Java Mongodb driver
The Java drivver along with the python is the most developed one, so you can check it in the driver DOCS. Usually the idea (structure of the commands) is the same as in the shell you just need helpers to construct the command. In Java this documentation can make some hints about how it works:DOCS so for $push: Mongoshell DOCS example: db.students.update( { name: "joe" }, { $push: { scores: 89 } } ) Where { name: "joe" } is a query identifing the right document to update and the scores is an array field and 89 will be abbended. Java DOCS example: check out this question : (MongoDB Java) $push into array $elemmatch: Mongoshell DOCS example: check out this question:Covert MongoDB query into Java $slice: Mongoshell D

Categories : Mongodb

Retrive a set of documents from array in MongoDB using Java driver
You can do it in Java as follows. Mongo mongo = new Mongo("localhost:27017"); DB db = mongo.getDB("myDB"); DBCollection coll = db.getCollection("myCollection"); DBObject statusQuery = new BasicDBObject("status", true); DBObject elemMatchQuery = new BasicDBObject("$elemMatch", statusQuery); DBObject fields = new BasicDBObject(); fields.put("items", elemMatchQuery); fields.put("name", 1); fields.put("config", 1); DBCursor cur = coll.find(new BasicDBObject(), fields); while (cur.hasNext()) { DBObject obj = cur.next(); // Get fields from object }

Categories : Java

MongoDB Text Search AND multiple search words
Give a try to: db.supplies.runCommand("text", {search:""printer" "ink""}) Also, here's a quote from docs: If the search string includes phrases, the search performs an AND with any other terms in the search string; e.g. search for ""twinkle twinkle" little star" searches for "twinkle twinkle" and ("little" or "star"). Hope that helps.

Categories : Mongodb

How to Represent Objects with Multiple Fields in the MongoDB Java Driver
Turns out one great way to do this is the following: BasicDBObject project = new BasicDBObject("$project", new BasicDBObject("sleep", new BasicDBObject().append("date", 1).append("hours", 1))); Then you can call your aggregation command as follows: AggregationOutput output = collection.aggregate(commandOne, commandTwo, Project, CommandThree); Hope this helps :)

Categories : Java

Translating MongoDB query to a MongoDB java driver query
I haven't checked the syntax. Also I don't know if your query works or not but here's my try. //unwind DBObject unwind = new BasicDBObject("$unwind", "$scorearray"); // Now the $group operation DBObject groupFields = new BasicDBObject("player", "$player"); groupFields.put("venue", "$scorearray.venue")); groupFields.put("score", "$scorearray.score")); DBObject group = new BasicDBObject("$group", new BasicDBObject("_id", groupFields)); //sort DBObject sort = new BasicDBObject("$sort", new BasicDBObject("_id.score":1)); //secondgroup DBObject secondGroupFields = new BasicDBObject("_id", "$_id.player") secondGroupFields.put("maxScore", new BasicDBObject("$last":"$_id.score")); secondGroupFi

Categories : Mongodb

How can MongoDB java driver determine if replica set is in the process of automatic failover?
I don't know the Java driver implementation itself, but I'd do catch all MongoExceptions, then filter them on getCode() basis. If the error code does not apply to replica sets failures, then I'd rethrow the MongoException. The problem is, to my knowledge there is no error codes reference in the documentation. Well there is a stub here, but this is fairly incomplete. The only way is to read the code of the Java driver to know what code it uses…

Categories : Mongodb

MongoDB Aggregration Framework and Java Driver making $or condtion work
I have done this in javascript. I did wrap the $or object with a $match object. I wonder if you need to do something similar: DBObject matchCriteriaTransmitter = new BasicDBObject("someKey": "someValue") .append("someKey": "someValue"); DBObject matchCriteriaReceiver = new BasicDBObject("someKey": "someValue") .append("someKey": "someValue"); BasicDBList or = new BasicDBList(); or.add(matchCriteriaTransmitter); or.add(matchCriteriaReceiver); DBObject matchCriteria = new BasicDBObject("$match", or);

Categories : Java

Mongodb : find matching elements in an array with given attributes using java driver
You can do it as follows : DBObject query = new BasicDBObject("playerHistories.playerId", "52307b8fe4b0fc612dea2c6f"); DBObject statusQuery = new BasicDBObject("event", "WonGame"); DBObject elemMatchQuery = new BasicDBObject("$elemMatch", statusQuery); DBObject fields = new BasicDBObject(); fields.put("playerHistories", elemMatchQuery); fields.put("initTime", 1); fields.put("startTime", 1); fields.put("endTime", 1); DBCursor cur = coll.find(query, fields);

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.