w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
mongodb, sorting by geoNear and date?
There's no direct way to use $near or $nearSphere and sort by another field, because both of these operators already sort the results of doing a find(). When you sort again by 'date', you're re-sorting the results. What you can do, however, is grab results from the $nearSphere incrementally, and sort each set of results. For example: function sortByDate(a, b) { return a.date - b.date; } // how many results to grab at a time var itersize = 10; // this will hold your final, two-way sorted results var sorted_results = new Array(); for (var i=0, last=db.coll.count(); i<last-itersize; i+=itersize) { var results = db.coll.find( {"date":{$gte:date}, // longitude, then latitude "location":[lng, lat]} ).skip(i).limit(itersiz

Categories : Mongodb

mongodb pymongo geonear results loop
$geoNear is supposed to return a documents, at least this is what the documentation claims: http://docs.mongodb.org/manual/reference/aggregation/geoNear/ "$geoNear returns documents in order of nearest to farthest from a specified point and pass the documents through the aggregation pipeline."

Categories : Python

MongoDB geoNear Aggregation - Order of Operations
Here's how $geoNear works: It gets a cursor to documents whose coordinates satisfy the maxDistance requirement. It then iterates over the cursor and for each document checks if it matches the query requirement. If it doesn't, it skips it and moves to the next document. It does this until it finds limit-many documents or the end of the cursor. Note that this is the limit argument to the $geoNear command, not the $limit operation specified later in the aggregation pipeline. The default limit is 100, so if you don't specify limit you are getting the first 100 documents that match query and whose coordinates satisfy maxDistance, sorting those 100 documents by created_at, and then taking the first 5. When you specify limit:100000, you are getting the first 100000 documents that match query and

Categories : Mongodb

Creating a Mongodb replicaset in an AWC VPC
see "Updating DNS Support for Your VPC" at http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-dns.html It's likely your VPC was created before the DNS Hostname support flag was available. Set it to True.

Categories : Mongodb

How do I configure mongodb replicaset using elastic IP's in EC2?
You should never use an Elastic IP for internal traffic like replication. You will be charged $0.01/GB for this traffic, whereas using the internal IP would be free. If you're using something like replica sets, you really should be running in a VPC. Unlike normal EC2 instances, instances in an VPC keep the same private IP addresses and Elastic IP addresses even when stopped.

Categories : Mongodb

mongodb: how to check which node I connected on replicaSet
1) use mongostat command, which will tell you how many different operations ( query, insert, update, delete, command, etc ) are coming to the server You will find that primary is not getting any 'query' operation but secondaries will. mongostat -u<user-name> -p<password> 2) Use mongosniff, to know the queries coming to the server

Categories : Java

MongoDB as windows service and setting up replicaSet
You can set up replica set and MongoDB service at the same time on Windows. Since you have already set up a replica set, you are aware that you need to have a data directory and a log file for each replica set member. If you are running all replica set members on a single machine, each replica set member must be assigned a different port number. The sample provided is for development or functional testing only. Setting up all replica set members on a single machine will constitute a single point of failure in addition to being a total performance drag. Create a configuration file for each replica set member including data directory, log file, port number, and replica set name. For example, I have a replica set of 3 members, one primary Mongodb running on port 27017 and two secondary,

Categories : Mongodb

MongoDB ReplicaSet on windows azure - Sockect exception error
This is old, but just in case someone else stumbles across this. You need to set the TCP/IP keep alive times different from the stock Linux configuration if you are running under Azure: echo 45 > /proc/sys/net/ipv4/tcp_keepalive_time echo 30 > /proc/sys/net/ipv4/tcp_keepalive_intvl echo 20 > /proc/sys/net/ipv4/tcp_keepalive_probes

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

Spring data MongoDb configuration
I suspect that you may have an authentication issue, try specifying the credentials of your mongodb when configuring your db-factory. I have added my configuration below to clarify <mongo:mongo host="127.0.0.1" port="27017" /> <mongo:db-factory id="mongoDbFactory" dbname="${db.name}" username="${db.username}" password="${db.password}"/> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> </bean>

Categories : Mongodb

spring data mongodb and jpa transaction
This might be what you want to achieve: http://static.springsource.org/spring-data/mongodb/docs/current/reference/html/mongo.cross.store.html However it ties the two entities strictly together.

Categories : Mongodb

Access to DAO in model - Spring Data MongoDB
Should just try to : @Component @Document( collection = "item" ) public class Item { @Id private ObjectId id; private Integer authId; @DBRef private Author author; /* Others setters and getters */ }

Categories : Java

spring data mongodb query document
I can't reproduce your problem, which suggests that the issue is with the values in the database and the values you're passing in to the query (i.e. they're not matching). This is not unusual when you're trying to match dates, as you need to make sure they're stored as ISODates in the database and queried using java.util.date in the query. I have a test that shows your query working, but I've made a number of assumptions about your data. My test looks like this, hopefully this will help point you in the correct direction, or if you give me more feedback I can re-create your problem more accurately. @Test public void shouldBeAbleToQuerySpringDataWithDates() throws Exception { // Setup - insert test data into the DB SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'

Categories : Java

Spring Data MongoDB: update using dot-notation
My mistake was that I didn't realize that id in is() part of query criteria must be ObjectId. For some reason Spring Data does automatic conversion from ObjectId to BigInteger, but not from BigInteger to ObjectId. If someone knows how to convert it manually, please answer this question

Categories : Java

Not an managed type for Spring Data Mongodb
In the same project we were also using mysql and it was scanning the package: com.example.repositories. This caused the issue and once we changed it to com.example.repositories.mysql it was solved.

Categories : Spring

How do I update Object with Spring Data and MongoDB?
You could probably do both 'find' and 'update' operations in one line. mongoTemplate.updateFirst(query,Update.update("Name", name),Person.class) You can find some excellent tutorials at Spring Data MongoDB Helloworld

Categories : Spring

Spring Data Mongodb POJO mapping
I think you can achieve it through this mapping (If I understood your question correctly): class Person { String name; int age; } class Outer { @Field("columns") List<Person> persons; }

Categories : Mongodb

spring-data mongodb custom implementation PropertyReferenceException
The problem is solved. This error appears when the Impl class is named incorrectly. The Impl class has to be named according to the repository class. So the names have to be following for this example: com.eerra.core.common.service.UserRepositoryInterface.java (main repository) com.eerra.core.common.service.UserRepositoryInterfaceImpl.java (implementation of custom repository methods) com.eerra.core.common.service.UserRepositoryInterfaceCustom.java (interface with custom methods) See the answer here: Spring-Data: mongoTemplate vs MongoRepository

Categories : Spring

Spring -Data MongoDB issue with field which is an interface
This is really bad idea to define interfaces as field in data object. Interface means possibility of some object to do something, but don't provide any information about fields. Do you really need to use interfaces? Can you avoid this? Even using abstract class definition will be better idea. P.S. off course, my answer can't be marked as correct answer in any case.

Categories : Java

Spring-Data MongoDB Update all document fields
I am not sure that I 100% understand your question but it seems that you trying to migrate your data from a SQL database using Hibernate into MongoDB using Spring-Data. We recently migrated all of the binary data in our application from Apache Jackrabbit into MongoDB also with Spring-Data. In addition there was one instance where we were still storing some binary data in our SQL database which was also migrated: We migrated this data in the following manner: Retrieve all the entities required from hibernate. Create a new instance of your MongoDB document. Loop through all of these entities copying the data from hibernate entities onto the MongoDB document. Call MongoOperations#save() for each document. You also mentioned something about updating: To update a particular document just

Categories : Java

Spring Data MongoDB: BigInteger to ObjectId conversion
You probably want to write a custom Spring converter BigInteger => ObjectId and ObjectId => BigInteger. See the doc part here: http://static.springsource.org/spring-data/data-document/docs/current/reference/html/#d0e2670 ------UPDATE------ It seems that this kind of converter already exists in the Spring-Data-MongoDB library: http://static.springsource.org/spring-data/data-document/docs/1.0.0.M1/api/org/springframework/data/document/mongodb/SimpleMongoConverter.ObjectIdToBigIntegerConverter.html So you just have to specify it in your Spring configuration.

Categories : Java

How to use low-level driver APIs with Spring Data MongoDB
you can do it this way @Autowired MongoDbFactory factory; DB local = factory.getDB("local"); DBCollection oplog = local.getCollection("oplog.$main"); DBCursor lastCursor = oplog.find().sort(new BasicDBObject("$natural", -1)).limit(1); Where MongoDbFactory is an interface provifed by spring-data-mongo that can obtain a com.mongodb.DB object and access allthe functionality of a specific MongoDB database instance your configuration file should contain these informations : <bean id="mongoFactoryBean" class="org.springframework.data.mongodb.core.MongoFactoryBean"> <property name="host" value="127.0.0.1"/> <property name="port" value="27017"/> </bean> <bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFacto

Categories : Spring

How does one run Spring XD in distributed mode?
Communication between the Admin and Container runtime components is via the messaging bus, which by default is Redis. Make sure the environment variable XD_HOME is set as per the documentation; if it is not you will see a logging message that suggests the properties file has been loaded correctly when it has not: 13/06/24 09:20:35 INFO support.PropertySourcesPlaceholderConfigurer: Loading properties file from URL [file:../config/redis.properties]

Categories : Spring

Spring Data MongoDB - java.net.SocketException: Connection reset
is dbserver your real hostname? Is a firewall blocking it? can you get to mongodb from command line? from a GUI client? See: What's causing my java.net.SocketException: Connection reset?

Categories : Java

how to use spring data mongodb repository query annotation for updating
Spring-data is a framework for general purpose that provides a very basic support to CRUD operations. If you need complex operations, like update using any $operator, you'll need to implement a custom repository to it.

Categories : Mongodb

How to prevent race conditions in a distributed nodejs web servers architecture backed by mongodb
You can use $set and $setOnInsert update operators to achieve that. From MongoDB $setOnInsert docs: If an update operation with upsert: true results in an insert of a document, then $setOnInsert assigns the specified values to the fields in the document. If the update operation does not result in an insert, $setOnInsert does nothing. and If the db.collection.update() with upsert: true had found a matching document, then MongoDB performs an update, applying the $set operation but ignoring the $setOnInsert operation. so, this should do the trick: var now = Date.now(); Users.update({ _id: 1 }, { $set: { updatedAt: now }, $setOnInsert: { createdAt: now } }, {upsert: true}, function(err, doc) { // resultant doc is available here })

Categories : Node Js

spring distributed database transaction manager
Sounds like you want to use a ChainedTransactionManager. Spring has implemented one of these for neo4j, so you can take the code out of the project. There was a good article on how to do this, but cant find it anymore. But perhaps this is enough to get you started..

Categories : Database

Spring Data MongoDB - Aggregation Framework - invalid reference in group Operation
The problem is not PDch or pd.PDch. For some reason the code is not using the Aggregation.DEFAULT_CONTEXT to get the field reference. This is happens when ever there is more than one field. Code works correctly if you only have one group field.

Categories : Mongodb

Spring Data MongoDB how do I set auto-connect-retry="true" with javaconfig style?
Simply do the following: Mongo mongo = new Mongo(); mongo.getMongoOptions().setAutoConnectRetry(true); Generally speaking, the MongoOptions type exposed contains all the settings you can apply through the namespace.

Categories : Spring

How to check the distributed data over hdfs
You can make use of web interface option available in hadoop. Using that you will be able to see every information about hdfs, how many nodes are present, how many are dead/alive, storage usage and all such. Hope it helps

Categories : Hadoop

mongo DB geoNear aggregation framework
The geoNear query uses a cursor and iterates over the index on demand, whereas the aggregation operator geoNear builds up the result in memory. Speed wise there is not going to be much of a difference, but memory wise you'd likely be better off using the query operator geoNear. If you don't need many documents than the difference is negligible. geoNear (aggregation) does have the possibility to also add the distance to the returned document, something that the query operator doesn't support.

Categories : Mongodb

How to design a canonical data model in a distributed platform?
If you are using Camel as (light weight) ESB, I think there isn't too much things to worry. Inside the camel routes you could just keep the format that best suits the case, you can even have more than one format running in parallel for some solutions (e.g. you could use the Java Bean to do some business logic but you could also use XSTL to transform the message into XML and XPath to get a better decouple and do some processing CBR). If you need to work a lot with the Java Bean model, I would recommend you to create a project that you could extract the model from the JSON, so you could control the version (with Maven, for example) of this artifact and that could be the canonical model for the Java applications (you would need to update this project if the JSON requests changes a lot). Crea

Categories : Rest

Jmeter 2.9 in distributed testing mode - cannot see response data in View Results Tree
Since JMeter 2.9: Distributed testing now uses MODE_STRIPPED_BATCH, which returns samples in batch mode (every 100 samples or every minute by default). Note also that MODE_STRIPPED_BATCH strips response data from SampleResult, so if you need it change to another mode (mode property in jmeter.properties) Usually full responses are not useful during load test and impact negatively performances of JMeter, so be sure you really need them

Categories : Performance

How can we know that how many nodes we need inside a Replicaset?
There is no exact answer to your question, but considering following factors can be useful: the volume of data you need to store average load on your server the peak load on your server what is the application access patters total number of indexes you have / need what is the percent of queries that can be processed using indexes. willingness to read from secondaries. You can run benchmarking based on some dummy data and figure out the the best solution for your use case. Hope this helps!

Categories : Mongodb

pymongo MongoClient connect to ReplicaSet
The MongoClient class only connects to a single host, as the documentation (http://api.mongodb.org/python/current/api/pymongo/mongo_client.html) says: Create a new connection to a single MongoDB instance at host:port. You need to use the MongoReplicaSetClient class that you've already discovered to work with a Replica Set.

Categories : Mongodb

Spring MongoDb ContextLoaderListener
One possible reason that you might have another version of spring-core jar along with 3.2.3.RELEASE in your classpath, a possible transitive dependency. CachingMetadataReaderFactory.clearCache() was added as a part of Spring Core 3.2.0.RELEASE. Having lower version of spring-core might therefore cause this problem. So, adding an explicit spring-core 3.2.3.RELEASE dependency like the one below might just solve this problem: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency>

Categories : Java

setting up spring security with mongoDb
You may have an incorrect version of spring-core pulled in via transitive dependencies. Try forcing a concrete version by adding: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.2.0.RELEASE</version> </dependency> And you don't need spring-orm for MongoDB. ORM stands for Object-Relational Mapping, and MongoDB is not relational. Also do use JUnit 4!

Categories : Java

Spring MongoDB Criteria update
query will get you the index of the collection array which matches query criteria. With your data structure, you need two array indexes, one for contacts and one for collection, which is not possible (as far as I know). You need to know the position of either the contacts array item or the collection array item. Let's assume you know the position of the contacts array item. if it is 0th position, here is your complete query: query = new Query(new Criteria().andOperator( Criteria.where("_id").is(myClassId), Criteria.where("contacts.collection.value").is("2"), Criteria.where("contacts.collection._class").is("SubClass2")); update.set("contacts.0.collection.$.value", "3"); mongoTemplate.updateFirst(query, update, MyClass.class);

Categories : Java

Spring MongoDB XML Configuration with credentials fails
Just in case anyone else comes across this issue... I was using spring-data-mongodb version 1.2.1-RELEASE. I upgraded to 1.3.0.M1 (currently the most recent milestone build) and the issue went away. Just as an FYI... I was having write problems with the writeConcern set to FSYNC_SAFE: <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongo" ref="mongo"/> <constructor-arg name="databaseName" value="${mongo.db}"/> <constructor-arg name="userCredentials" ref="mongoCredentials"/> <property name="writeConcern" value="FSYNC_SAFE"/> </bean> so I changed it to the following and it's finally working: <property name="writeConcern"> <util:constant static-field="com.mongo

Categories : Xml



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