Questions tagged [jongo]

Jongo allows to query in Java as in Mongo shell; unmarshalling results into Java objects (by default with Jackson).

Jongo

Using Mongo with its Java driver can be tricky: querying, mapping results and handling polymorphism require lots of code. Some libraries aim to simplify this (like Morphia), but none allow to query in a shell fashion.

Jongo tries to fill that need, querying with the use of strings "{age: {$gt: 18}}" and unmarshalling results into Java objects (by default with Jackson):

DB db = new Mongo().getDB("dbname");

Jongo jongo = new Jongo(db);
MongoCollection friends = jongo.getCollection("friends");

friends.find("{age: {$gt: 18}}").as(Friend.class)
111 questions
3
votes
1 answer

find by Object Id in Jongo

I know this question is incredibly basic... I'm sorry in advance. I can't do a 'find by ID' for Mongo using Jongo. I tried Iterator all = db.getCollection("mongoTest").find("{'_id':…
Wolfman Joe
  • 799
  • 1
  • 8
  • 23
2
votes
1 answer

Too many parameters error on the following $in query

I'm using jongo API - org.jongo.MongoCollection is the class. I have list of object ids and converted the same as ObjectId[] and trying to query as follows collection.find("{_id:{$in:#}}", ids).as(Employee.class); The query throws the exception -…
Kathiresa
  • 421
  • 2
  • 6
  • 15
2
votes
1 answer

find 5 days old documents with $lt operand in MongoDB with Jongo - query returns empty result

Data in MongoDB collection has format { "_id" : ObjectId("57a1bfc103c8851a98dba3b2"), "createdOn": NumberLong("1470218177561"), "name": "Raja", "description": "Employee Raja" } Mongo DB Query and Results > new Date(1470218177561); …
Kathire
  • 53
  • 1
  • 8
2
votes
0 answers

Mapping flat DB documents to nested classes in Morphia

I am porting a Java application that used to use Jongo to communicate with MongoDB to Morphia + new MongoDB Java Driver. In the database there are flat documents like: { "_id" : ObjectId("56c2e5b9b9b6e9753d4f11de"), "field1" :…
silmeth
  • 680
  • 1
  • 8
  • 22
2
votes
1 answer

how to get inserted object id in jongo with mongodb

Account entity public class Account { @MongoObjectId private String _id; private String name; public String get_id() { return _id; } public void set_id(String _id) { this._id = _id; …
Rakesh Varma
  • 151
  • 1
  • 2
  • 14
2
votes
2 answers

What does the @Id annotation?

I have a class that has this note, @Id, what is the use of it? package oknok.validacao.resources; import org.jongo.marshall.jackson.oid.Id; public class Validacao { @Id String id; String email; String instancia; String…
Daniela Morais
  • 2,125
  • 7
  • 28
  • 49
2
votes
1 answer

MarshallingException when trying to mapping a Class to a document on playframwork

I'm writing a Play 2.3.2 application in Java and I'm using Jongo as driver for MongoDB. After do some changes to my code my application gives me runtime errors. The error is given to the fourth lines of the getUser method. This is my used…
alberto adami
  • 729
  • 1
  • 6
  • 25
2
votes
1 answer

What is the different between MongoDB plugins for Play framework2?

I'm starting to learn MongoDB, integrated with Play framework 2. I goggled about how to integrate it with Play framework2 and finally found many plugins available: MongoDB Jackson Mapper Jongo Play2 Morphia plugin I'm quite confused which one…
lvarayut
  • 13,963
  • 17
  • 63
  • 87
2
votes
1 answer

Query entire collection in jongo

I'm trying to get all results from this collection and them trying to print the first one: MongoCollection musics = JNDIManager.getJongoCollection("musics"); Iterable all = musics.find().as(MusicObject.class); where MusicObject…
2
votes
1 answer

Jongo Update query is not working

I am new with Jongo and mongoDB. I am trying to update my mongodb document with the new Java object but its not working. Is there any dependancy/versioning issue of jongo? I couldn't find any solution. Here is my code String query =…
Amit
  • 451
  • 2
  • 6
  • 19
2
votes
1 answer

Mongodb / Jongo sorting then limit, vs, limit then sorting

Are these two guaranteed to be the same: collection.limit(10).sort("{score: -1}") vs collection.sort("{score: -1}").limit(10) The second one does a global sort, and returns the top 10. Is the first one guaranteed to do the same, or may it just…
Heptic
  • 3,076
  • 4
  • 30
  • 51
2
votes
1 answer

How to add items to Mongo array using Jongo?

I'm using Jongo to query mongodb. The problem is that when I try to add items to an array field I get the error that says HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException:…
2
votes
2 answers

unmarshall aggregate result with Jongo

I am using the MongoDB aggregate framework to query a document, the results is the following: { "result" : [ { "_id" : "luke", "times" : 8 }, { …
nuvio
  • 2,555
  • 4
  • 32
  • 58
1
vote
1 answer

Getting "Regular expression is invalid: missing )" error using json in MongoDb

I am running the query given below. db.CollectionName.find({'serviceName':{'$regex':'^(ALBUMIN$','$options':'si'}}) I am getting the following error. Error: error: { "ok" : 0, "errmsg" : "Regular expression is invalid: missing )", …
Manshavi Kumar
  • 133
  • 2
  • 9
1
vote
0 answers

How to retrieve the timestamp from the ObjectID field in mongodb document in java?

I want to query all the documents in a collection to get the timestamp of each document from the ObjectID, as there is no separate createdAt fieldin the documents. How do i structure the query for the same in java?
Emma Vaze
  • 17
  • 8