morphia

Morphia projection behavior for instance variable with default value

こ雲淡風輕ζ 提交于 2019-12-24 00:07:16
问题 I'm not sure if its the way Morphia is designed but here it goes... Student.class (methods omitted) @Entity(value = "students", noClassnameStored = true) public class Student { @Id private String id = new ObjectId().toString(); private String name; private String city = "London"; // Default Value } NOTE: That I have assigned a DEFAULT value to Instance variable city . Now the code... Student s1 = new Student("James Bond"); // London IS his default city ds.save(s1); Student s2 = new Student(

Morphia query with or operator

淺唱寂寞╮ 提交于 2019-12-23 07:45:58
问题 I want to know how to write a Morphia mongodb query with 'or' operator I wrote mongodb query like this and this work fine db.Inv.find({$or:[{sug_id:2},{grp_id:2}]}) But i got confused when i try to write this in morphia, following query is wrong but how can write something similar to this List<Inv> invs = ds.find(Inv.class).field("grp_id").hasAnyOf(grpId).or(field("sug_id")).hasAnyOf(grpId).asList(); Thanks 回答1: not sure why hasAnyOf() is in there but try this: Query<Inv> query = ds.find(Inv

MongoDB schema design - finding the last X comments across all blog posts filtered by user

邮差的信 提交于 2019-12-23 02:19:23
问题 I am trying to reproduce the classic blog schema of one Post to many Comment s using Morphia and the Play Framework. My schema in Mongo is: { "_id" : ObjectId("4d941c960c68c4e20d6a9abf"), "className" : "models.Post", "title" : "An amazing blog post", "comments" : [ { "commentDate" : NumberLong("1301552278491"), "commenter" : { "$ref" : "SiteUser", "$id" : ObjectId("4d941c960c68c4e20c6a9abf") }, "comment" : "What a blog post!" }, { "commentDate" : NumberLong("1301552278492"), "commenter" : { "

unauthorized db lock type:-1

谁说我不能喝 提交于 2019-12-22 18:10:53
问题 One of popular hosting in beta testing mode with MongoDB. Locally my application works fine. But after deployment in hosting I have the following problem: Tomcat: Jan 27, 2012 1:24:32 PM org.apache.catalina.core.ApplicationContext log SEVERE: Exception while dispatching incoming RPC call com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract void ...' threw an unexpected exception: com.mongodb.MongoException: unauthorized db:mongodb-logger lock type:-1 client:192

How can I sort MongoDB query results by inner array size?

跟風遠走 提交于 2019-12-21 17:57:02
问题 I'm using Morphia to access mongoDB. I need to get a list of objects by the length of the inner array. Does any one have an idea how it can be done without getting all the collection to Java and sort it there? 回答1: You should create extra field with nested array size and use $inc to update this field. Also you can use $where , but it very slow. You search by nested array length like this: db.coll.find({ $where: "this.nestedArray.length > 3" }); But as i said better to create an extra field.

How to retrieve last update time of each document in MongoDB?

帅比萌擦擦* 提交于 2019-12-21 03:17:13
问题 I would like to know if there is a way to get the last update/modify time of data (i.e documents) in a collection in MongoDB. More clearly, I want to make a query to retrieve all documents updated after a particular time. Is there any possible ways to retrieve this last modified timestamp in MongoDB? Note: For newly created documents, I know that we can retrieve the timestamp from the objectId, but for an update, the id is going to be same. Does MongoDB store the last update time for each

Is there any orm-like library for mongodb in scala?

戏子无情 提交于 2019-12-20 20:03:23
问题 It seems only the casbah we can use in scala, but I hope there is a orm-like library for scala, like morphia for java, or something else. Is there any? I don't want to use morphia in scala because I have to convert java collections to scala UPDATE I've tried some of them, but still not find a proper one. Some are hard for scala newbies to get started. FINALLY Finally, I chose mongo-scala-driver, its awesome. Thanks to everybody. 回答1: There are two solid options: Salat, which is designed to

Querying Morphia by Id

孤街浪徒 提交于 2019-12-19 07:48:31
问题 I am using Morphia, the Pojo mapper for MongoDB, and I find difficult a task that in my view should be very simple: getting an object by id. I am able to find all the objects in a collection but I cannot figure out the simple task of querying using an id I got from the list. I am actually talking about the ObjectId. If I try to render it in JSON I see 回答1: This question seems incomplete. It also seems like the answer to you question is on the Morphia QuickStart page. Seems to be as simple as

Mongodb: `com.mongodb.MongoSocketReadException: Prematurely reached end of stream` with morphia

不打扰是莪最后的温柔 提交于 2019-12-18 15:43:29
问题 I've a simple data structure (the Transaction referenced below) to be inserted into mongodb: {"amount":111,"debitAcc":"588188286231743e7d5c923d","type":"CHARGE"} An I got the following error stack: com.mongodb.MongoSocketReadException: Prematurely reached end of stream at com.mongodb.connection.SocketStream.read(SocketStream.java:88) at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:494) at com.mongodb.connection.InternalStreamConnection

Does MongoDB provide a way to generate sequential values?

回眸只為那壹抹淺笑 提交于 2019-12-13 07:44:31
问题 I'm developing a web application in Java and storing some data on a MongoDB using Morphia. Besides the ObjectId , I need to persist a sequential value for each document of a collection. This sequential value must be unique in the collection. My first approach would be create a collection to store only the sequential value and synchronize the method which gets and increments the value. Are there any better ways to do it? 回答1: Generally in MongoDB, you would not use an auto-increment pattern as