morphia

Morphia not applying sparse option to my index

大城市里の小女人 提交于 2019-12-13 05:14:28
问题 I'm trying to use Morphia to interface with MongoDB, and my Morphia entity looks like this: @Entity(some params about storing the entity) public class Entity implements Serializable { <Some other fields here> @Indexed(options = @IndexOptions(unique = true, sparse = true) ) private String field; <Some other fields here> } I would like this field to be unique if present, but not required (and not unique if not present; multiple entries should be able to exclude this field). My understanding of

Gradle dependencies not working in IntelliJ

坚强是说给别人听的谎言 提交于 2019-12-12 19:56:25
问题 I'm working on an intelliJ project with my friends where we use MongoDB & Morphia. We have the mongo stuff as a dependency in Gradle, as you can see here: I didn't set this stuff up, I cloned it from a repository. But my other friends have gotten this to work - all on Windows, OSX, and Linux. And only one of them set it up. The issue is that it doesn't know what Morphia / MongoDB is (for example, the imports don't work). What I have done: Resync Gradle Run the Gradle.build file Reclone the

How to deserialize json document obtained from mongoDB into a POJO?… (Migrating from Morphia to Java Mongo Driver 3.0)

笑着哭i 提交于 2019-12-12 13:29:06
问题 BACKGROUND Initially, Morphia was being used to interact with a mongo database. This was fine and worked nicely, but there was one caveat... Some mapping exception was being spilled and clogging the logs. See my Unresolved Question on that particular issue. <=== This didn't stop the application from functioning correctly. Morphia helped in getting the documents mapped to their corresponding entities ( basically POJOs ) and these were easily rendered to the Views. However, after much

How to prefer reads on secondaries in MongoDb

我是研究僧i 提交于 2019-12-12 08:54:13
问题 When using mongodb in a replica set configuration (1 arbiter, 1 primary, 2 slaves); how do I set a preference that read be performed against the secondaries and leave the primary only for writes? I'm using MongoDb 2.0.4 with Morphia. I see that there is a slaveOk() method, but I'm not sure how that works. Morphia http://code.google.com/p/morphia/ Details My Mongo is set with the following options: mongo.slaveOk(); mongo.setWriteConcern(WriteConcern.SAFE); I am attempting to use the following

What is the correct way to use operators in Mongo aggregation pipelines with Morphia

我们两清 提交于 2019-12-12 05:29:12
问题 I have two documents at this stage in my aggregation pipeline which are: { "_id" : "Piers Morgan", "entities" : ["Sexism", "Charlotte Hawkins","Red carpet"] } { "_id" : "Gareth Bale", "entities" : ["Sergio Busquets", "Real Madrid C.F.", "EFL Cup", "Copa del Rey"] } I wish simply to return a projection which is the id and the size of the array, using Morphia in Java. In Mongo this can be done using: { $project: { count : {$size : "$entities"} } } In Morphia I have attempted: .project

Morphia - remove a reference object

十年热恋 提交于 2019-12-11 19:47:16
问题 Lets say a Blog class with Comment Object as reference. Comment Object has Id, Comment Date, Comment. (Reference) NOT EMBEDDED. How do I remove a comment? 回答1: Assuming a blog post entity can have multiple comments, but each comment belongs to exactly one blog post. First you'll need to remove the reference: BlogPostEntity blog = mongoDataStore.find(BlogEntity.class) .field("comments") .hasThisElement(new Key<CommentEntity>(CommentEntity.class, comment.getId())) .get(); if (blog != null) {

Morphia is there a difference between fetch and asList in performance wise

混江龙づ霸主 提交于 2019-12-11 02:29:40
问题 We are using morphia 0.99 and java driver 2.7.3 I would like to learn is there any difference between fetching records one by one using fetch and retrieving results by asList (assume that there is enough memory to retrieve records through asList ). We iterate over a large collection, while using fetch I sometimes encounter cursor not found exception on the server during the fetch operation, so I need to execute another command to continue, what could be the reason for this? 1-)fetch the

Manual Conversion of 3rd Party Class With Morphia

时间秒杀一切 提交于 2019-12-11 01:40:58
问题 Long story short: Is it possible to write a type converter for a 3rd party library class with Morphia? Long story: I'm new to Morphia. I have an entity class which contains a field typed javax.activation.MimeType . When I try to save instances of my class, Morphia complains it "can't serialize class javax.activation.MimeType". I tried writing a TypeConverter and adding it to the list of converters but it didn't work. Here are the code pieces: Entity.class @Entity @Converters(MimeTypeConverter

Morphia - using hasAllOf and hasThisElement together

坚强是说给别人听的谎言 提交于 2019-12-11 01:22:51
问题 I have a mongo collection named 'comment' which has documents which have a structure similar to this : { "_id" : ObjectId("9873214jkhdkfjdsf8324"), "nm" : "test", "sts" : 1, "updby" : NumberLong(0), "tags" : [ { "name" : "women", "rank" : 1, "type" : 3 }, { "name" : "men", "rank" : 1 }, { "name" : "clothing", "rank" : 2, "type" : 1 } ] I want to query the collection using a mongo query which would look like this : db.comment.find({"tags":{ $all:[ {"$elemMatch":{"name" : "women", "type" : 3}},

How to add indexes in mongoDB project with Morphia framework

…衆ロ難τιáo~ 提交于 2019-12-10 22:31:41
问题 i'm working on a gwt project, that uses mongoDB as database, and morphia framework to work with mongodb. I already finished the basic dao of my classes and now i want to insert indexes in my classes to speedup the mongo searches. I looked the morphia documentation, and i saw that haves a @Indexed that makes this, but i don't know how to really use the index in a search. The morphia will automatically use the index? Does anyone have a good example of index in a real project ? (the hello world