w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Mongo DB sorting exception - too much data for sort() with no index
Try creating a compound index instead of two indexes. db.collection.ensureIndex( { 'loc':'2d','lastActiveTime':-1 } ) You can also suggest the query which index to use: db.collection.find(...).hint('myIndexName')

Categories : Mongodb

Run mongo index command from terminal, solutions for a very large index
You should use the background option. db.collection.ensureIndex({ text: 'text', background: true }) From mongodb's documentation: Builds the index in the background so that building an index does not block other database activities. More information here http://docs.mongodb.org/manual/reference/method/db.collection.ensureIndex/

Categories : Mongodb

Why is my mongo query not using index only?
You are using arrays and subdocuments. Covered Indexes dont work with either of these. From the mongo docs: An index cannot cover a query if: any of the indexed fields in any of the documents in the collection includes an array. If an indexed field is an array, the index becomes a multi-key index index and cannot support a covered query. any of the indexed fields are fields in subdocuments. To index fields in subdocuments, use dot notation. For example, consider a collection users with documents of the following form: http://docs.mongodb.org/manual/tutorial/create-indexes-to-support-queries/

Categories : Windows

How can i exclude a mongo index from a query?
You can't exclude indexes, you can only specify the use of one. However, MongoDB empirically tests indexes with your query by checking the search speed of the query against all indexes. It then determines what index to use based on these results. Can you please run the query with .explain(true) to show all the query plans. Regards, Charlie

Categories : Mongodb

Optimizing Compound Mongo GeoSpatial Index
I played with this for a number of days and got the result I was looking for. Firstly, given that action types other than "PLAY" CAN NOT have a location the additional query parameter "actionType==PLAY" was unnecessary and removed. Straight away I flipped from "time-reverse-b-tree" cursor to "Geobrowse-polygon" and for my test search latency improved by an order of 10. Next, I revisited the 2dsphere as suggested by Derick. Again another latency improvement by roughly 5. Overall a much better user experience for map searches was achieved. I have one refinement remaining. Queries in areas where there are no plays for a number of days have generally increased in latency. This is due to the query looking back in time until it can find "some play". If necessary, I will add in a time range

Categories : Mongodb

Deployment software for node.js & mongo
We use CircleCi for our continuous integration. Circle makes it easy to do deployment workflows based on the branch that is pushed. Plug for CircleCi. We had a Jenkins server, please just quit using it because it was a hassle compared to a hosted service. We do a similar process for one of our tool sets. We use the master branch for development, and the release branch for production. The exception is a successful test run builds our release branch, not a human clicking a button. Do something like the following: Develop your code in a master branch Changes to your master branch are pushed to your development machines You create a button that executes an action to merge into the release branch, and push back to origin: git fetch origin/release && git rebase origin/master &a

Categories : Node Js

Node.js Application with Mongo.db on Heroku
It's probably better to create a local .env file and use Foreman (installed with the Heroku Toolbelt) to start your application. You should put this in a local .env file: DATABASE_URI=mongodb://localhost/minidatabase and edit your source code to reference the database as: mongoose.connect(process.env.DATABASE_URI) Then start you app using: foreman start If you don't know how to install foreman, have a look at https://toolbelt.herokuapp.com/ Also, remember to run the following command to set the URI in Heroku: heroku config:set DATABASE_URI=[the mongolab URI goes here]

Categories : Javascript

Deleting a subdocument by Id in Mongo using node.js
If you mean how you should implement removal of a comment: you first retrieve the article document using articleId, and then you can find and remove the sub-document: // find article ... // find the comment by id, and remove it: article.comments.id(commentId).remove(); // since it's a sub-document of article, you need // to save the article back to the database to // 'finalize' the removal of the comment: article.save(function(err) { ... });

Categories : Node Js

How to get a instance of db from node-mongo native driver?
You could write a wrapper, a new module where you store the db instance, something similar to this: //db.js var HOSTNAME = ... var PORT = ... var db = module.exports = {}; var instance; db.connect = function (){ ... instance = <db_instance>; }; db.disconnect = function (){ ... instance = null; }; db.instance = function (){ return instance; }; Now, every time you need the db instance retrieve it by doing: var db = require ("./path/to/db"); db.instance ();

Categories : Node Js

Is there a way to group Mongo data or do I need to do it in node/javascript?
This is as close as I got without spending a ton of time on it. I don't know all of the requirements or how much your data varies. For instance, is recipient always a single value even though it's wrapped in an array? Regardless, it should be close enough for you to take the rest of the way. It's grouping by the recipient and the subject, and just sending the message along. The reduce function creates the container, and for each message passed in, pushes the value into trainingblock. db.collection.mapReduce(function() { var recipient = this.recipient[0]; emit(recipient + "#" + this.subject, { message: this.message }); }, function(key, values) { var parts = key.split('#'), recipient = parts[0], subject = parts[1], block = { recipient: recipient, subject: subject, t

Categories : Json

How to use node-mongodb-connection for connect-mongo
This is how it works for me, var connectionString = "mongodb://username:password@localhost:27017/db_name"; var dbOptions = { server:{ 'auto_reconnect': true, 'poolSize': 20, socketOptions: {keepAlive: 1} } } // For long running applictions it is often prudent to enable keepAlive. Without it, // after some period of time you may start to see "connection closed" errors for what // seems like no reason. MongoClient.connect(connectionString, dbOptions, function(err, db) { if(err){ console.log(err); } app.use(express.session({ store:new mongoStore({db: db}), secret: 'secret' })); }) This works perfectly for me and it will not give you not authorized issues as well. Previously we don't need to give keepAlive option and it wor

Categories : Node Js

Mongo query to return the last update time of each node
Along the same lines of Dylan's comment, you should probably provide some more information for an optimal response. In addition to his comments, one that comes to mind is if you do full scans every time you look for heartbeats. That is, you could potentially group some nodes in a doc as an array (or create new collections based on access patterns) and manipulate in the app layer.

Categories : Mongodb

how to get the index of a child node under a parent node using python?
Using xml.etree.ElementTree: import xml.etree.ElementTree as ET root = ET.fromstring('''<?xml version="1.0"?> <BCPFORMAT ... </BCPFORMAT>''') # Accessing parent node: http://effbot.org/zone/element.htm#accessing-parents parent_map = {c: p for p in root.getiterator() for c in p} child = root.find('.//*[@ID="1"]') print(list(parent_map[child]).index(child)) # => 0 Using lxml: import lxml.etree as ET root = ET.fromstring('''<?xml version="1.0"?> <BCPFORMAT ... </BCPFORMAT>''') child = root.find('.//*[@ID="1"]') print(child.getparent().index(child)) # => 0

Categories : Python

Python Mongo Sorting based on field within a field
Subfields in documents can be accessed by using dot notation (e.g. outerfield1.innerField). In Mongo shell you can do this sorting by using: sort({'outerField1.innerField': -1}) If you are on Python, you may need to write instead: sort([("outerField1.innerField": -1)]) The reason you need to do this is that Python's dict is an unordered data structure. For details, see: http://stackoverflow.com/a/10242305/117919

Categories : Python

Authenticating users on mongo, node, passport, and heroku. Stops working after a few days
Since: the user would come back from mongo as guestuser ... you should probably put some logging and/or error handling here: passport.deserializeUser(function(id, done) { User.findOne(id, function (err, user) { done(err, user); }); }); to help you track it down. Since you're just getting started, I'd suggest you take a look at winston and loggly if you want to explore tooling up your logging in node/heroku. Your application looks very "bouncy", to coin a phrase -- lots of redirects that seem sort of all over the place. Have you looked at fnakstad's technique for node/angular authentication? (Note that the github page references two blog posts that explain things). It might give you some ideas on how to get things under control.

Categories : Node Js

Unique index in C++ map with custom sorting
how can I find an item only by the unique_id? the problem with this question is that the list contains Foo classes and ordered by priority. this makes it problematic to search for items by unique_id. what i'm suggesting is to create a new std::map std::map <int, foo> uniqueId_To_FooClass; and when adding to bla a new item, add it to uniqueId_To_FooClass. that way you can find a foo class by unique_id I would more like to store the priority in the value (not as the key), but I don't know how I can sort by value then. Is a std::map the right class/template for that? As far as I can remember, std::map will give you the iterator that will go through the items sorted by the key. Only way to go through the sorted items by the value, and still use the map, is to rewrite whole

Categories : C++

Multi-Index Sorting in Pandas
A hack would be to change the order of the levels: In [11]: g Out[11]: Sales Manufacturer Product Name Product Launch Date Apple iPad 2010-04-03 30 iPod 2001-10-23 34 Samsung Galaxy 2009-04-27 24 Galaxy Tab 2010-09-02 22 In [12]: g.index = g.index.swaplevel(1, 2) Sortlevel, which (as you've found) sorts the MultiIndex levels in order: In [13]: g = g.sortlevel() And swap back: In [14]: g.index = g.index.swaplevel(1, 2) In [15]: g Out[15]: Sales Manufacturer Product Name Product Launch Date Apple iPod 2001-10-23 34 iPad 2010-04-03

Categories : Python

How to obtain the index permutation after the sorting
Why not put some satellite data? Instead of sorting the numbers, just sort pairs of numbers and their indices. Since the sorting is first done on the first element of the pair, this shouldn't disrupt a stable sorting algorithm. For unstable algorithms, this will change it to a stable one. But note that if you try sorting this way it generates the index while sorting, not after. Also, since knowing the permutation index would lead to a O(n) sorting algorithm, so you cannot do it faster than O(nlogn).

Categories : C++

sorting 2d array in node js
Based on the answer http://stackoverflow.com/a/8837511/1903116 post.sort(function(a, b){ var keyA = a.date, keyB = b.date; if(keyA < keyB) return 1; if(keyA > keyB) return -1; return 0; }); console.log (post);

Categories : Node Js

XSL sorting of two node sets
With XSLT 2.0 you could easily do <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="Results"> <xsl:copy> <xsl:apply-templates select="School"> <xsl:sort select="min(Location/Distance/number(.))"/> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="School"> <xsl:copy> <xsl:apply-templates select="Name"/> <xsl:apply-templates select="Location"> <xsl:sort select="number(Distance)"/>

Categories : Sorting

2 dimensional array sorting using column index
The below code should work String[][] theArray = new String[][]{{"Enter values","Enter values"}, {more values, more values}}; Comparator<String[]> comparator= new Comparator<String[]>() { Arrays.sort(theArray, new Comparator<String[]>(){ @Override public int compare(String[] o1, String[] o2) { return o1[0].compareTo(02[0]); } }); Arrays.sort(theArray, comparator); Casting should always try to be avoided. Although it should work to use your approach (object and cast to string) so you probably have some other error in your code. Anyway, it's better to explicit tell the compiler that you are sorting Strings if you know that this is what you will be sorting.

Categories : Java

Postgresql Sorting a Joined Table with an index
You need to rethink your approach. Where to begin? This is a clear example, basically of the limits, performance-wise, of the sort of functional approach you are taking to SQL. Functions are largely planner opaque, and you are forcing two different lookups on data_table for every row retrieved because the stored procedure's plans cannot be folded together. Now, far worse, you are indexing one table based on data in another. This might work for append-only workloads (inserts allowed but no updates) but it will not work if data_table can ever have updates applied. If the data in data_table ever changes, you will have the index return wrong results. In these cases, you are almost always better off writing in the join as explicit, and letting the planner figure out the best way to retri

Categories : Postgresql

Sorting 2 dimensional arrays in Java - skipping the first index
A trivial way would be: int firstBurst = jobs[0][2]; jobs[0][2] = Integer.MIN_VALUE; Arrays.sort(jobs, new Comparator<int[]>(){ public int compare(int[] a, int[] b) { // don't use subtraction, this can lead to underflows return a[2] < b[2] ? -1 : (a[2] == b[2] ? 0 : 1); } }); jobs[0][2] = firstBurst; Simply set the burst of the first item to Integer.MIN_VALUE (the integer equivalent of minus infinity). That way, it guaranteed that the first item is the smallest, so after sorting it will still be the first element. After sorting, reset the burst of the first item to its original value. EDIT By checking the documentation to verify that Arrays.sort is stable, I accidentally found the simplest version to solve this problem: use Arrays.sort(T[] a,

Categories : Java

Sorting Array list of equal length Arrays based on index
I would suggest you to do two specific things: Take in consideration the data-set you would need to sort, that usually helps in sorting faster. (as mentioned in the comment, if its limited range do a counting sort) Start using multi-threading (actually called worker threads). YES JAVASCRIPT DOEST SUPPORT IT NOW. So do a merge sort and start showing results partially. For more details on how to use multi-threading, refer worker threads. One good tutorial I can think of is http://ejohn.org/blog/web-workers/

Categories : Javascript

mongo + passenger: right way to reconnect to database from within rails? how to ensure optimal mongo performance?
The method to handle this changed between Mongomapper versions. The correct way now is to use Mongomapper's convenience method in your initializer: MongoMapper.connection.handle_passenger_forking See the source on Github for implementation details.

Categories : Ruby On Rails

Algorithm for mongo objectid filed in mongodb and how to get last 24 hour data from mongo collection
Is there any way to get objectids that are genrated in last 24 hours in mongo collection based on time stamp on objectid You can call JavaScript code such as: date = new Date() date.setDate(date.getDate() - 1) yesterday = Math.floor(date.getTime()/1000).toString(16) db.coll.find({_id : {$gt : new ObjectId(yesterday + "0000000000000000")}} , {_id:1}) The first and second statements are straightforward: yesterday's date. Third row creates a 4-Byte Hex String of yesterday. Which are the 4 leftmost bytes of ObjectId. Then, you pad the 8 rightmost bytes of the ObjectId with zero's as you don't care about those. These are mac address(3), pid(2) and a running counter(3) All you have to now is query your collection (coll in the example) and return the _id's what is the algorithm to

Categories : Mongodb

Mongo Java finding Maching record in mongo array
We would need to get holistic information about your application in order to tell you if you're making the right modeling decisions; however, I can help you with your current query. In order to match multiple attributes within the same element of an array, you should use the $elemMatch operator (http://docs.mongodb.org/manual/reference/projection/elemMatch/). eg) collection.find({users:{$elemMatch:{username:uname,password:password}}});

Categories : Java

Mongo C++ Driver: mongo/client/dbclient.h: No such file or directory
The line app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory indicates that g++ is having difficulty finding the installed headers. In the tutorial that you linked to, the box below the suggested compilation command states You may need to use -I and -L to specify the locations of your mongo and boost headers and libraries. I'll assume that the installation procedure placed your header files in /usr/local/include and libraries (e.g. libmongoclient.a) in /usr/local/lib. Then, try adapting the compilation command to read g++ -I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/tutorial.cpp -o tutorial

Categories : C++

Mongo java maching two or more values in mongo array
Your document structure might get in the way here. How do you distinguish the user logging in? If you get a match, it will return the whole document, with all users. Anyhow, to query with multiple comparisons: BasicDBObject query = new BasicDBObject(); List<BasicDBObject> parts = new ArrayList<BasicDBObject>(); parts.add(new BasicDBObject("users.user_name", uname)); parts.add(new BasicDBObject("users.password", password)); query.put("$and", parts); DBCursor cursor = collection.find(query); while (cursor.hasNext()) { System.out.println(cursor.next()); }

Categories : Java

Update Mongo Collection Using hadoop-mongo & PIG
The solution is to use MongoUpdateStorage: https://github.com/alabid/mongo-hadoop/blob/issues/pig/mongo-update-storage/pig/README.md Works like a charm

Categories : Hadoop

Index on Node Properties in Neo4j <2.0
You can index some property of each user such as a userId to easily find all user nodes (http://docs.neo4j.org/chunked/stable/indexing.html) For the cars, do you simply wish to search for cars of a certain year and color? Or do you want to use those to do more detailed querying? If you just want a straight search, then you might consider the index there as well. Otherwise the year nodes and maybe even color nodes would be the way I'd do it. Note that you can use both an index (index on year and color), as well as the year/color nodes. The index might be helpful to find a starting set of nodes before you do more involved querying. If color is important in these queries, then having the car related to a color would be much better than the color as a property on the car (because the propert

Categories : Neo4j

Utilizing Google's appsforyourdomain
Unfortunately I was unable to solve the problem in Java. However, after investigating the Python implementation of the API I was able to match the functions well enough to get by with the PyDoc info. The original goal was to export Gmail mailbox contents. The solution, in Python, is as follows: from gdata.apps.audit.service import AuditService audit_service = AuditService(domain="example.com") audit_service.ClientLogin(admin_user, passwd) audit_service.createMailboxExportRequest(user="target_user") #check the status audit_service.getAllMailboxExportRequestsStatus() As typical Google/gData caveats you need to make sure your user account has appropriate permissions, you have enabled service, the API is authorized to use the service, gdata is install, updated, and in your PYTHONPATH, an

Categories : Java

Recursively add a node at a certain index on Linked List
You have two errors in your recursive method: Before calling addAtRec(obj, k, current); you should decrease k by 1, so it would be better to call k-- before this line. Once you have reached the base case (when k == 0)and executed the logic to add the new node, your recursive method must stop, probably with a simple return; statement. In this case, you're not stopping it so you will call it every time until get to the end of your list. Based on these 2 advices, your code should look like: public void addAtRec(Object obj, int k, ListNode current) throws ListIndexOutOfBoundsException { //always use braces even for single line block of code if(current.nextNode == null && k != 0) { throw new ListIndexOutOfBoundsException(); } if(k == 0) { ListNod

Categories : Java

Glossary type facet from Node Index
This solved my problems. Its adding another field to index and you can create facet out of it. function wtc_glossary_search_api_alter_callback_info() { $callbacks['wtc_glossary_alter_add_first_letter_title'] = array( 'name' => t('First letter of listing title'), 'description' => t("This module provides first letter of title for glossary view."), 'class' => 'WtcAlterAddFirstLetter', ); return $callbacks; } /** * Search API data alteration callback that adds the first letter of title for glossary mode */ class WtcAlterAddFirstLetter extends SearchApiAbstractAlterCallback { public function alterItems(array &$items) { foreach ($items as $id => &$item) { if (!isset($item->FIELD_YOU_NEED)) { $item->search_api_title_first_lett

Categories : Drupal

LibGdx: Utilizing a Gesture Listener
From the wiki: A GestureDetector is an InputProcessor in disguise. To listen for gestures, one has to implement the GestureListener interface and pass it to the constructor of the GestureDetector. The detector is then set as an InputProcessor, either on an InputMultiplexer or as the main InputProcessor I admit that is rather dense. But a bit farther down on the wiki you'll see: Gdx.input.setInputProcessor(new GestureDetector(new MyGestureListener())); To rephrase the above in hopefully less dense English: Your GestureHandler instance is passed to a Libgdx GestureDetector instance. That object will accumulate "raw" inputs and convert them into higher-level "gestures". To get the raw inputs, it needs to be installed where the raw inputs will be delivered to it. The most

Categories : Java

What is the most effective way of utilizing JSP pages as a view?
Well, I found the answer after speaking to an experienced colleague of mine. Posting it here for any other beginners who might be getting aboard my ship: <table border="5" cellpadding="5" cellspacing="5"> <tr><td>EmpId</td><logic:iterate name="id" id="id"> <td width="8"><bean:write name="id"/></td> </logic:iterate></tr> <tr><td>Name</td><logic:iterate name="name" id="name"> <td width="8"><bean:write name="name"/></td> </logic:iterate></tr> </table> The table tag is used for presentation. The key tag here is the logic:iteration tag. It helps you iterate through the list(s) you pass to the page. Two separate logic:iterate tags were created for each list. In ord

Categories : Jsp

Utilizing UITouch tapCount in applicationDidEnterBackground
Not possible. Once the app goes into background mode - the screen no longer belongs to the app - but the home screen (Or whatever other app is on screen) - also, due to the way apps on iOS devices are sandboxed - this would be crossing that line.. Why do you need to register taps outside of the app?

Categories : IOS

Utilizing the click on point event
Below is the code that uses the event of a point being clicked on a Shield UI Chart: events: { pointSelect: function pointSelectHandler(args) { var Information= "Point Value: " + args.point.y; alert(Information); }, Don't forget to enable the point selection: enablePointSelection:true,

Categories : Javascript

jquery: select element with classname and node index
Is this the actual problem? Yes. If you access a selected element via bracket notation, you get the raw DOM element back. DOM elements don't have an animate method. By passing the DOM element to jQuery again ($($('.myclass')[v])) you are creating a jQuery object (again). You can avoid this and use .eq to get a jQuery object for the element at that index: $('.myclass').eq(v); It would be better to keep a reference to the selected elements outside the loop though: var indizes = [0, 3]; var $elements = $('.myclass'); $.each(indizes, function(i, v) { $elements.eq(v).animate({ left: 100 }, 1000); }); Alternatively, you can use .filter to filter out the elements you want to animate, which at least looks a bit more concise: $('.myclass').filter(function(i) { retu

Categories : Javascript

In Neo4j (using Lucene index) how can I find what a Node has been indexed under?
In Neo4j 1.9 you can't. In Neo4j 2.0, you can get the Labels and Indexes on a node, e.g. CREATE n:Person{name:'Jim'} Make an index CREATE INDEX on :Person(name) List labels MATCH n RETURN LABELS(n)

Categories : Neo4j



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