Questions tagged [morphia]

Morphia is a lightweight type-safe library for mapping Java objects to/from MongoDB.

Features

  • Easy to use, and very lightweight. Reflection is used once per type and cached for good performance.
  • Datastore and DAO access abstractions, or roll your own.
  • Type-safe, and Fluent Query support with (runtime) validation.
  • Annotation-based mapping behavior; there are no XML files.
  • Extensions: Validation (jsr303) and SLF4J Logging.

Useful links

870 questions
77
votes
5 answers

Unit testing with MongoDB

My database of choice is MongoDB. I'm writing a data-layer API to abstract implementation details from client applications - that is, I'm essentially providing a single public interface (an object which acts as an IDL). I'm testing my logic as I go…
wulfgarpro
  • 6,666
  • 12
  • 69
  • 110
36
votes
4 answers

MongoDB Composite Key

I'm just getting started with MongoDb and I've noticed that I get a lot of duplicate records for entries that I meant to be unique. I would like to know how to use a composite key for my data and I'm looking for information on how to create them.…
Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131
36
votes
8 answers

Are persistence annotations in domain objects a bad practice?

I realize that persistence frameworks such as Morphia and Hibernate rely on annotations on domain objects to do their magic. At some level, it seems to me that this is inserting persistence concerns into the domain layer which is something we're…
HolySamosa
  • 9,011
  • 14
  • 69
  • 102
32
votes
4 answers

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

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…
Sadish Kumar
  • 531
  • 1
  • 7
  • 14
31
votes
5 answers

Can I use String as ID type for mongodb document?

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…
Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
16
votes
1 answer

Difference between _id & $oid ; $date & IsoDate in mongo database

We are using mongo db to store certain records in production database. We see our records having "_id" : { "$oid" : "50585fbcb046b2709a534502"} in production database , while we see same record as "_id" : ObjectId(" 50585fbcb046b2709a534502 ") in…
Kumar Manish
  • 1,166
  • 1
  • 16
  • 28
14
votes
4 answers

How do Morphia, Mongo4j and Spring data for MongoDB compare?

I'm interested in how to they compare to each other, what's more mature, has more features, better for some use cases. My own use case is to create a real-time monitoring service (think Chartbeat) but if you can talk about other use cases please do…
Catalin Braescu
  • 651
  • 1
  • 6
  • 5
14
votes
2 answers

MongoDB: $in with an ObjectId array

Just a quick question about something I've just experienced and I'm still thinking about why: mongos> db.tickets.count({ "idReferenceList" : { "$in" : [ { "$oid" : "53f1f09f2cdcc8f339e5efa2"} , { "$oid" : "5409ae2e2cdc31c5aa0ce0a5"}]}}); 0 mongos>…
lcappa
  • 329
  • 2
  • 4
  • 14
13
votes
2 answers

Saving enum into mongoDB

Is there a way to save enum into the mongoDB? I want to save something like: public enum SnapshotType { EVENT, MEMORY }
inglor
  • 327
  • 1
  • 3
  • 12
12
votes
2 answers

Is it possible to store multiple types of Objects into 1 mongodb collection?

using document oriënted database mongodb and the Object Document Mapper (ODM) morphia Lets say we have 3 different classes; Object, Category and Action. These object are all stored in the collections; objects, categories and actions. Category and…
Marcel
  • 1,494
  • 1
  • 23
  • 33
11
votes
2 answers

morphia and howto update existing document field

I am trying to update a document. I cannot see/understand how to do it from this page: http://www.mongodb.org My Document looks as following: (could be some error here) @Entity public class UserData { private Date creationDate; private…
Erik
  • 5,039
  • 10
  • 63
  • 119
11
votes
1 answer

Morphia query with or operator

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…
user1573690
  • 361
  • 1
  • 7
  • 21
11
votes
2 answers

a field name "ClassName" is being inserted into mongodb by morphia

I'm pretty new to mongodb and morphia, after starting using it, I realize that there is a extra part in mongodb document, the record contains a filed name "ClassName" with value of the class that morphia mapped. { "_id" :…
nightograph
  • 2,179
  • 5
  • 31
  • 49
10
votes
4 answers

Can't find a codec for my class

I have simple class named Signal. Class looks as follows: public class Signal { private String id; private Date timestamp; public String getId() { return id; } public void setId(String id) { this.id = id; } …
Darshan Puranik
  • 1,055
  • 3
  • 14
  • 36
10
votes
3 answers

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

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…
Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
1
2 3
57 58