morphia

Using the $in operator through Morphia - doing it wrong?

怎甘沉沦 提交于 2019-12-07 06:36:43
问题 I have the following Play Framework entity (using Morphia for persistence) as part of a generic blogging app: @Entity public class Comment extends Model { ... @Reference @Indexed public SiteUser commenter; public static List<Comment> getLastCommentsByUsers(final List<SiteUser> users) { final Query<Comment> query ds().createQuery(Comment.class); query.field(commenter).hasAnyOf(users); return query.asList(); } } SiteUser: @Entity(noClassnameStored=true) public class SiteUser extends

Query MongoDB for ordered distinct values

折月煮酒 提交于 2019-12-07 01:06:03
问题 I am using Morphia Java driver for querying a MongoDB that contains a collection of the following form: MyCollection { TypeA TypeB } I want to retrieve all distinct values of TypeB which I do using the following code: DBCollection myCol = getDatastore().getCollection(MyCollection.class); List typeBs = myCol.distinct("TypeB"); Above code works as expected, but list of distinct values is of course not sorted. I have experimented with the following code: DBCollection myCol = getDatastore()

Can I use String as ID type for mongodb document?

ε祈祈猫儿з 提交于 2019-12-06 18:07:59
问题 I am using java/morphia to deal with mongodb. The default ObjectId is not very convenient to use from Java layer. I would like to make it a String type while keep the key generation process using ObjectId, say _id = new ObjectId.toString() . I want to know if there is any side effects doing it this way? For example, will it impact the database performance or causing key conflicts in any means? Will it affect the sharding environment ... 回答1: You can use any type of value for an _id field

MongoDB - Index not being used when sorting and limiting on ranged query

怎甘沉沦 提交于 2019-12-06 13:49:16
I'm trying to get a sorted list of items using a ranged query on a collection containing bulletin-board data. The data structure of a "thread" document is: { "_id" : ObjectId("5a779b47f4fa72412126526a"), "title" : "necessitatibus tincidunt libris assueverit", "content" : "Corrumpitvenenatis cubilia adipiscing sollicitudin", "flagged" : false, "locked" : false, "sticky" : false, "lastPostAt" : ISODate("2018-02-05T06:35:24.656Z"), "postCount" : 42, "user" : ObjectId("5a779b46f4fa72412126525a"), "category" : ObjectId("5a779b31f4fa724121265164"), "createdAt" : ISODate("2018-02-04T23:46:15.852Z"),

unauthorized db lock type:-1

眉间皱痕 提交于 2019-12-06 13:20:39
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.168.23.159 at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385) at com.google

MongoDB elemMatch subdocuments

被刻印的时光 ゝ 提交于 2019-12-06 06:30:20
问题 I have the following data structure { "_id" : ObjectId("523331359245b5a07b903ccc"), "a" : "a", "b" : [ { "c" : { "_id" : ObjectId("5232b5090364678515db9a82"), "d" : "d1" } }, { "c" : { "_id" : ObjectId("5232b5090364678515db9a83"), "d" : "d2" } } ] } For the following queries, mongo returns > db.test.find({b : {$elemMatch : {'c.d': 'd1'}}}).count(); 1 > db.test.find({b : {$elemMatch : {c: {d: 'd1'}}}}).count(); 0 Unfortunately, for the following statements B b = new B(); C c = new C(); b.c = c

Mongo connection leak with morphia

ぃ、小莉子 提交于 2019-12-06 01:33:05
I have a Servlet with static Mongo = new Mongo() and Morphia morphia = new Morphia() objects. Each time GET is invoked, I do the following: doGet(...){ ... datastore = morphia.createDatastore(mongo, dbName); ... } I don't close datastore , because there is no close method. Each time i invoke the servlet, number of used connections in mongo grow: { "current" : 113, "available" : 706, "totalCreated" : NumberLong(122) } > db.serverStatus().connections { "current" : 115, "available" : 704, "totalCreated" : NumberLong(124) } > db.serverStatus().connections { "current" : 116, "available" : 703,

In Morphia how can i update one embedded Object inside an ArrayList

柔情痞子 提交于 2019-12-05 21:19:08
Really new to Using Mongodb with Morphia and see many advanced answers how to do this. I want to do it simple if it's possible and I have this @Embedded Object called fileObjects that contains Files Objects. I Cannot update the fields inside the Files . I want to update only one field f.ex the String fileHash . @Entity public class BatchData { @Id private ObjectId id; @Embedded public ArrayList<Files> fileObjects = new ArrayList<Files>(); } UPDATE.. Reading the wiki at Morphia Updating dont "really" say how to do this only when the array contains Integer like this: @Embedded List<Integer>

MongoDB / Morphia saves technical id as ObjectId although it's a String in Java

别等时光非礼了梦想. 提交于 2019-12-05 14:44:20
I've got two kinds of documents in my MongoDB: clients and codes. Each code refers to one client. Clients have to be stored explicitly by an administrator, therefore I have to store them separate and cannot put them into a code document. code -> client Now MongoDB / Morphia saves technical ids of clients as ObjectId, whereas codes refer to clients with a technical id of type String. I am able to search a code by a given client id, but at the runtime I'll get a error message, because Morphia cannot inject the client. I assume it's because of the different id types. code { client.$id: String }

Mongo Java drivers & mappers performances

天大地大妈咪最大 提交于 2019-12-05 13:05:11
Mongo in Java can be used with several tools: the 10gen official driver an alternative async Java driver a mapper — a library built on top of a driver — Morphia , Jongo ... ( see complete list ) Is there some benchmarks comparing mappers to drivers performances and one versus each others? Unfortunately, there are no benchmarks that I am aware of. The driver home page is here (but I'm guessing that you probably know that) and the Java Language Center containing all information related to Java for MongoDB. There is quite a bit of work going on with the Java drivers at present afaik but no