w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
$near $unwind mongodb geospatial
I found a solution. First I tried use $match and $near, however, without success. Then I read about $geoNear aggregation and tried put as the last parameter of my pipeline, however, according MongoDB page: "You can only use $geoNear as the first stage of a pipeline." I was in doubt about $unwind that I needed, but, I found a parameter which helps me in an array localization. My shell code: db.EducationalInstitution.aggregate( {$geoNear: {near: [-15.795758,-47.892312], maxDistance: 50/111.12, distanceField: "addresses.calculated", includeLocs: "addresses.locs", niqueDocs: true}}, {$project: {"name": 1, "addresses.state": 1, "addresses.locs": 1}} ); My Java code: public BasicDBList findByCoordinates(double longitude, double latitude){ BasicDBObject cmdB

Categories : Mongodb

MongoDB - Geospatial intersection performance
After tearing my hair out trying to figure out the best way to accomplish better performance in MongoDB, I decided to try our existing standard DB, SQL Server. I guess my low expectations for SQL Server's geospatial functionality were unfounded. The query ran in < 12 seconds without an index, and didn't scale up exponentially like MongoDB for larger drawn polygons. After adding an index, most queries are in the 1 second range. I guess I'll be sticking with what I know. I really had high hopes for MongoDB, but geospatial performance is severely lacking (or severely under-documented on how to improve it).

Categories : Mongodb

MongoDB: geospatial query with additional conditions
I've tried the query and it seems to work as you intend with the $elemMatch operator. I think the problem is that you have a typo in your query where address is used instead of addresses. Your query should look like: db.coll.find({ 'addresses.loc':{$near:[lat,lng]}, addresses: { $elemMatch: {context: "office"} } });

Categories : Mongodb

Efficiently sorting the results of a mongodb geospatial query
When there is a huge result matching particular box, sort operation is really expensive so that you definitely want to avoid it. Try creating separate index on relevance field and try using it (without 2d index at all): the query will be executed much more efficiently that way - documents (already sorted by relevance) will be scanned one by one matching the given geo box condition. When top 10 are found, you're good. It might not be that fast if geo box matches only small subset of the collection, though. In worst case scenario it will need to scan through the whole collection. I suggest you to create 2 indexes (loc vs. relevance) and run tests on queries which are common in your app (using mongo's hint to force using needed index). Depending on your tests results, you may even want to

Categories : Mongodb

Using find() with geospatial coordinates in Mongoose (NodeJS+MongoDB)
I had to use the Mixed type and added some custom validation to ensure values were arrays and had a length of 2. I also checked for empty arrays and converted them to nulls because this is required when using sparse indices with 2dsphere. (Mongoose helpfully sets array fields to [] for you, which is not a valid coordinate!) var schema = new mongoose.Schema({ location: { type: {}, index: '2dsphere', sparse: true } }); schema.pre('save', function (next) { var value = that.get('location'); if (value === null) return next(); if (value === undefined) return next(); if (!Array.isArray(value)) return next(new Error('Coordinates must be an array')); if (value.length === 0) return that.set(path, undefined); if (value.length !== 2) return next(new Error('Coordinates should be of

Categories : Node Js

PyMongo/MongoDB - Geospatial Query for both Origin and Destination LatLon
Not sure about the actual MongoDB version that you're using but $within was deprecated and now you should be using $geoWithin: http://docs.mongodb.org/manual/reference/operator/geoWithin/ Also see the above link for further options. I'm not an expert on Python but I hope that $geoWithin will solve your problem.

Categories : Python

Does the MongoDB .Net driver version 1.8.2 support $geoWithin Geospatial Query Selector
The MongoDB C# driver still uses the (deprecated) $within as opposed to $geoWithin. Here is the relevant open JIRA ticket if you'd like to keep an eye on it. :)

Categories : Mongodb

How to get difference between two Dates in Symfony MongoDB?
You can use date_diff to calculate the difference: $diff = date_diff(new DateTime(), $member->getRegDate()); var_dump( $diff ); // « shows some properties. For more information, see the documentation on date_diff and DateInterval. BTW, you don't need to use "now" either, as that is the default behaviour.

Categories : Mongodb

Two MongoDB queries same result, what is the difference?
The difference is that $elemMatch finds items for one single array element. This solution: db.users.find({ "linkedProviders.userId": "1XXXXXXXX6", "linkedProviders.providerId": "facebook" }) Finds any user that has that userId and that providerId, but possibly in different items in linkedProviders, e.g., if linkedProviders[0].userId matches the first and linkedProviders[1].providerId matches the second part of the query, the full document (i.e., the user) will match that query. On the other hand, db.users.find({ "linkedProviders": { "$elemMatch": { "userId": "1XXXXXXXX6", "providerId": "facebook" } } }) will match only if the index values (0 and 1 in the previous example) are the same in the document, i.e., only if one array e

Categories : Mongodb

Difference between prelude and yesod with MongoDB
The problem is that GHCi runs your code in the IO monad, while your function is in the HandlerT App IO monad. But HandlerT is a monad transformer over the IO monad, so you can use lift to "promote" your IO action to a HandlerT App IO action. The type of lift is: lift :: (MonadTrans t, Monad m) => m a -> t m a In your case, t has to be HandlerT App and m has to be IO. So the correct code looks like this: getActivityR :: Handler Import.Value getActivityR = do pipe <- lift $ runIOE $ connect $ Host "XXXXX.mongolab.com" $ PortNumber 33317 access pipe master <databaseName> $ auth <username> <password> access pipe master <databaseName> allCollections returnJson $ object ["activity" .= ("abc" :: Text)] I don't know what your access is, so I

Categories : Mongodb

MongoDB difference between error code 11000 and 11001
The code 11001 does not exist in the 2.5/2.6 branch on GitHub, so if you're trying a 2.5 version than you can't create it. I did have a look at the code, but I can't find any path that shows the 11001 code either directly. The following few lines will show code 11001: db.so.drop(); db.so.insert( { foo: 5 } ); db.so.ensureIndex( { foo: 1 }, { unique: true } ); db.so.insert( { foo: 6 } ); The expected 11000: db.so.insert( { foo: 5 } ); E11000 duplicate key error index: test.so.$foo_1 dup key: { : 5.0 } And now to reach the 11001: db.so.insert( { foo: 6 } ); db.so.update( { foo: 6 }, { $set: { foo: 5 } } ); E11000 duplicate key error index: test.so.$foo_1 dup key: { : 5.0 } Still the original 11000, but: db.getPrevError(); { "err" : "E11000 duplicate key error index: test.so.

Categories : Mongodb

MongoDB difference between DateTime object and YYYY-MM-DD string
The advantage of DateTime is a few bytes less on disk. bson stores DateTime as an integer, but "2013-08-31" is a string, at 20 bytes right there. ISO-8601 (http://www.w3.org/QA/Tips/iso-date) is meant for being able to sort quickly. In this case, I would always store as datetime. edit: How time-consuming are you seeing this string-to-datetime conversion? Are you sure that is your bottleneck? I have a hard time believing the conversion is taking as long as you claim.

Categories : String

Find difference between 2 documents on mongoDB from the mongo shell
Just declare native javascript function that can compare two objects in a way you need, then write a code like this: obj1 = db.test.findOne({"_id" : ObjectId("5176f80981f1e2878e840888")}) obj2 = db.test.findOne({"_id" : ObjectId("5176f82081f1e2878e840889")}) difference(obj1, obj2) Some native javascript difference functions can be found here or here P.S. You can also load some third party js libs from shell like this: load("D:difference.js") Hope this help.

Categories : Mongodb

How to use MongoDB aggregation for general purpose set operations (union, intersection, difference)
The easiest of these three using aggregation is the intersection**. The general case for that can be done using aggregation like so: Intersection: db.colors.aggregate([ {'$unwind' : "$left"}, {'$unwind' : "$right"}, {'$project': { value:"$left", same:{$cond:[{$eq:["$left","$right"]}, 1, 0]} } }, {'$group' : { _id: {id:'$_id', val:'$value'}, doesMatch:{$max:"$same"} } }, {'$match' :{doesMatch:1}}, ]); The other two become a bit more tricky. To my knowledge there isn't a way of combining two separate fields in the same document together. It would be nice to have an $add, $combine, or $addToSet in the $project pipeline phase, but this doe

Categories : Mongodb

Cassandra: Geospatial support
The basic b-tree indexes are there in cassandra in the form of wide rows. PlayOrm has a complete SQL language on cassandra though with partitions so you are not joining billions of rows with billions of rows and instead join partitions. I imagine doing geospatial would be similar to what PlayOrm has but I am guessing. I mean is geospatial doable with b-tree's and such? If so, it just means you have to do a bit of heavy lifting. I know at one point, PlayOrm was considering adding some geospatial features but we never got around to it.....we would always accept work in that area though. later, Dean

Categories : Cassandra

SpatialIndexProvider in Neo4jclient for Geospatial Searches
As the lead of the Neo4jClient project, I can say that this is no currently on our roadmap. There's no particular reason for that beyond the fact that I don't use it personally and nobody has asked previously. To make it happen, your best options are: 1) Create an issue on https://bitbucket.org/Readify/Neo4jClient/issues 2) Describe the expected impact 3) Even better, send a pull request In the meantime, you can obviously do direct REST calls for the indexing operations but keep everything else going via Neo4jClient. Finally, it should be noted that our general direction is to support Cypher more and more. It would be good to align to any Cypher+Spatial plans, if they exist.

Categories : Misc

Integration of talend geospatial component
Download a fresh copy of the Talend Open Data zip (http://talend.dreamhosters.com/tos/release/V5.3.0/TOS_DI-r101800-V5.3.0.zip) Unzip the plugin into the plugins folder Start Talend. Do not start talend before step 2 is complete.

Categories : Misc

How to create an animation of geospatial / temporal data
Your question is a bit vague, but I will share how I have done this kind of animation in the past. Create a function that plots all the subject locations for one time slice: plot_time = function(dataset, time_id) { # make a plot with your favorite plotting package (e.g. `ggplot2`) # Save it as a file on disk (e.g. using `ggsave`), under a regular name, # frame001.png, frame002.png, see sprintf('frame%03d', time_index) } Call this function on each of your timeslices, e.g. using lapply: lapply(start_time_id:stop_time_id, plot_time) leading to a set of graphics files on the hard drive called frame001 to framexxx. Use a tool to render those frames into a movie, e.g. using ffmpeg, see for example. This is a general workflow, which has been already implemented in the anima

Categories : R

One-to-Many Geospatial Search Index Design in Solr
The geospatial multi-valued data is handled easily via location_rpt in Solr's out of the box schema. The trickier part here is the weighted tags. As a first cut, I'd index 3 fields, tags05 tags10 tags15, each with 3 separate query-time boosts (via edismax's qf param) of 0.5, 1.0, and 1.5 respectively. This is a discretization approach in which you loose some of the weight fidelity depending on how many buckets you have (3 shown here). If you can, avoid Solr 4 JOIN queries; they are often quite slow. The IDF scores would be a little bad due to the data being split up, so you might want to try a different similarity implementation for these fields that don't consider IDF, perhaps.

Categories : Mysql

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

How to convert geospatial Point(lat,lon) hash back to lat lon values?
The answer to your specific question is for you to index full-length geohashes to the precision you desire. No matter what your programming language of choice is, I'm sure you can find a library of code snippet to convert back & forth. Index it as string and facet on it. You are then faced with how to plot what could be a ridiculous number of points on a map in a scalable manner. You'll have to use spatial clustering / heat-map. See http://wiki.apache.org/solr/SpatialClustering

Categories : Solr

MongoDB errors: mongodb-10gen E: Sub-process /usr/bin/dpkg returned an error code (1)
This is due to some corruption within the package manager dpkg itself, this thread from Ask Ubuntu: http://askubuntu.com/questions/195950/package-system-broken-e-sub-process-usr-bin-dpkg-returned-an-error-code-1 lists some solutions, more specifically the editing of the status file has been noted as one that always works.

Categories : Linux

Nodejs, MongoDB (node-mongodb-native). FindAndModify finds doc, but doesn't update it
In findAndModify, there is one more parameter which you can set, to return the old document(before update) or new document ( after update ). I am guessing this must be the issue. For confirmation, for the existing findAndModify() command, after this command is run, check that updated document from the mongo console, it must be changed.

Categories : Node Js

Connecting from WSO2DSS to MongoDB, receiving error: java.lang.NoClassDefFoundError: com/mongodb/ServerAddres.
The missing class looks like ServerAddress (I assume the missing "s" is a copy-paste issue) which is in the MongoDB Java driver (mongo-java-driver). Make sure mongo-java-driver-2.xx.jar is on the runtime classpath. Note that the runtime classpath is not always the same as the compile time classpath.

Categories : Mongodb

query based on matching elements in DBRef list for mongodb using spring-data-mongodb
Querying for one element on an array is exactly like query for a field equality. You could read the MongoDB documentation here. So your query will be: new Query(Criteria.where("users.$id").is(new ObjectId(userId)))

Categories : Mongodb

NoSQLUnit MongoDB test: Spring Data MongoDB approach
Jaranda, Seems that your spring repository and nosqlunit are working on different databases. Try to modify your spring configuration to use the same database of nosqlunit. <mongo:db-factory id="mongoDbFactory" mongo-ref="mongo" dbname="test" />

Categories : Java

mongodb: java: How to update a field in MongoDB using expression with existing value
At the moment, MongoDB doesn't allow you to update the value of a field according to an existing value of a field. Which means, you can't do the following SQL: UPDATE foo SET field1 = field1 / 2; In MongoDB, you will need to do this in your application, but be aware that this is no longer an atomic operation as you need to read and then write.

Categories : Java

MapReduce, MongoDB and node-mongodb-native
The reason why the reduce function is never called is due to you emitting a single value for each key so there is no reason for the reduce function to actually execute. Here is an example of how you trigger the reduce function collection.insert([{group: 1, price:41}, {group: 1, price:22}, {group: 2, price:12}], {w:1}, function(err, r) { // String functions var map = function() { emit(this.group, this.price); }; var reduce = function(key, values) { return Array.sum(values); }; collection.mapReduce( map, reduce, { query:{}, // sort: {'count': -1}, // limit: 10, // jsMode: true, // verbose: false, out: { inline: 1 } }, function(err, results) { console.log("----------- 0") console.dir(er

Categories : Mongodb

Why does adding extra check in loop make big difference on some machines, and small difference on others?
One big difference between CPUs is the pipeline optimization The CPU can execute in parallel several instructions until reaches a conditional branch. From this point instead of waiting until all the instructions are executed, the CPU can continue with a branch in parallel until the condition is available and ready to be evaluated. If the assumption was correct, then we have a gain. Otherwise the CPU will go with the other branch. So the tricky part for a CPU is to find the best assumptions and to execute as many instructions in parallel as possible.

Categories : C++

What do blue-difference and red-difference chroma components mean in YCbCr color space?
The Cb and Cr components of the YCbCr, or YCC, color space are not immediately physically intuitive. Cb and Cr respectively represent the blue-difference and red-difference chroma signals as you noted. Chromaticity represents the perceptual deviation from the neutral, i.e. grayscale, so the greater the deviation, the higher the intensity of chroma. An image with low chroma is less colorful, and conversely. And so, Cb and Cr are one representation of changes in blue and red "colorfulness", respectively. Each colorspace has different advantages, mostly related to how sensitive channels to changes. For example, YCbCR is widely popular for its compressibility in the Cb and Cr channels by subsampling. Or, when doing things in computer vision like image matching using color-based methods, it is

Categories : Image

Find difference between rows of same column (difference between time data)
Try: DATEDIFF (mi, CAST(mc.login AS DATETIME), CAST(mp.login AS DATETIME)) as diff This will get difference in minutes SQLFiddle DEMO

Categories : Asp Net

Postgres sql 8.4 Use of Time Difference and Date Difference Separately
Here is the SQLFiddel Demo Below is the query which you can try select EmpHrs.ID_EMP, EmpHrs.Name, ( (EmpHrs.NOOFHRS*20)- (EmpHrs.NOOFHRS* JuneSuspension.MONTHSUSPENSION) ) as "June-2013", ( (EmpHrs.NOOFHRS*20)- (EmpHrs.NOOFHRS* JulySuspension.MONTHSUSPENSION) ) as "July-2013" from ( select ID_EMP,NAME, Extract(Hours from time_end-time_initial)+ Extract(Minutes from time_end-time_initial)/60 as NoOfHrs from schedule ) EmpHrs Left join (select ID_EMP,to_char(to_timestamp (Extract(Month from suspension_initial)::text, 'MM'),'Mon') as MonthIni,(suspension_end::date - suspension_initial::date)+1 MonthSuspension from suspension where Extract(Month from suspension_initial) = 6) JuneSusp

Categories : SQL

A difference-in-difference boxplot-like plot in Matlab
How about something along the lines of: x = rand(2, 1); % ? maybe just leave out? y = rand(2, 1); % [mean(Apre), mean(Apost)] e = rand(2, 1)*.2; % ? is this maybe [std(Apre), std(Apost)] errorbar(x, y, e, 'o-'); % You can leave off the x here if you don't need it hold all %Now repeat for B x = rand(2, 1); y = rand(2, 1); e = rand(2, 1)*.2; errorbar(x, y, e, '^-'); legend({'First series', 'Second Series'})

Categories : Matlab

I have a query in mongodb and the reference key's are in hashmap list , I need to process a simple query using java in mongodb
When you post code, it helps if you indent it, so it is more readable. As I mentioned to you on another forum, you need to go back and review the Java collection classes, since you have multiple usage errors in the above code. Here are a few things you need to do to clean up your code: 1) You don't need to use the itkey iterator. Instead, use: for (String key : likey) and get rid of all the itkey.next calls. Your current code only processes every second element of the List. The other ones are printed out. 2) Your HashMap will map a key to a Boolean. Is that what you want? You said you want to count the number of non-zero values for the key. So, the line: Boolean listone = table.distinct(keys).contains(nullvalue); is almost certainly in error. 3) When you iterate over the Ha

Categories : Java

Mongodb : find documents including references to sub-documents [node-mongodb-native]
MongoDB doesn't support joins so you have to query for the User details separately. If you're using node.js, Mongoose provides a populate feature to help simplify this so you can do something like the following to pull in the user details: Files.find().populate('Users_id')

Categories : Mongodb

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

Outputting difference in two pandas dataframes side by side - highlighting the difference
If your two dataframes have the same ids in them, then finding out what changed is actually pretty easy. Just doing frame1 != frame2 will give you a boolean DataFrame where each True is data that has changed. From that, you could easily get the index of each changed row by doing changedids = frame1.index[np.any(frame1 != frame2,axis=1)].

Categories : Python

find difference between lists and append difference to lists, but for 40 different lists - python
Sounds like you could use sets: >>> {1, 2, 3, 4, 5} & {2, 3, 4, 5, 6, 7} & {3, 4, 5} {3, 4, 5} & is the intersection operator for sets. Get a set of a list (this will remove duplicate elements with set(mylist). Edit: In the light of your comments, it seems what you need is some sort of union (the union operator being |), not an intersection. Here is a function that does what you wanted in your comment for 2 lists of lists: def function(first, second): first_set = {tuple(i) for i in first} second_set = {tuple(i) for i in second} return (first_set | {(i[0], 0) for i in second_set}, second_set | {(i[0], 0) for i in first_set}) >>> a = [(1,60),(3,90)] >>> b = [(2,30),(4,50)] >>> x, y = function(a, b) >>> pri

Categories : Python

Should I use MongoDB?
From my experience Mongo does ok with writes, but it's not spectacular. At a previous job, our production instance struggled quite a bit more with writes than reads. Mongo is very aggressive with allocating files on disk. Read this: http://docs.mongodb.org/manual/faq/storage/#why-are-the-files-in-my-data-directory-larger-than-the-data-in-my-database Eventually Mongo tries to grab 2GB at a time even if your database is empty. From my experience I found deletes to be pretty efficient. No real complaints, but then again we weren't deleting a lot of data. The horizontal scaling from my experience was pretty chatty, but it has to be to replicate data. The thing to read about is the difference between using a replica set or using sharding. The replication model/network activity is pretty di

Categories : Mongodb

MongoDB PHP (SUM)?
MongoDB's query language doesn't give us the ability to perform summations, but we can utilize its aggregation framework to do so. Given the following sample data: > db.stok.insert({ isbn:"foo", adet: 5 }) > db.stok.insert({ isbn:"foo", adet: 3 }) > db.stok.insert({ isbn:"foo", adet: 1 }) > db.stok.insert({ isbn:"bar", adet: 2 }) > db.stok.insert({ isbn:"bar", adet: 4 }) > db.stok.find() { "_id" : ObjectId("51cde94037a16345b5316987"), "isbn" : "foo", "adet" : 5 } { "_id" : ObjectId("51cde94437a16345b5316988"), "isbn" : "foo", "adet" : 3 } { "_id" : ObjectId("51cde94b37a16345b5316989"), "isbn" : "foo", "adet" : 1 } { "_id" : ObjectId("51cde95337a16345b531698a"), "isbn" : "bar", "adet" : 2 } { "_id" : ObjectId("51cde95637a16345b531698b"), "isbn" : "bar", "adet" : 4 } We

Categories : PHP



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