Questions tagged [mongojack]

Mongojack is a library that facilitates mapping between Java objects and MongoDB documents.

Since MongoDB uses BSON, a binary form of JSON, to store its documents, a JSON mapper is a perfect mechanism for mapping Java objects to MongoDB documents. And the best Java JSON mapper is Jackson. Jackson’s parsing/generating interface fits serialising to MongoDBs documents like a glove. Its plugins, custom creators, serialisers, views, pluggable annotators and so on give this mapping library a massive head start, making it powerful, performant, and robust.

Features

  • Deserialises queried objects directly from the MongoDB stream, making it one of the (if not the) fastest object mappers for MongoDB out there.

  • Uses Jackson for object mapping, so compatible with most Jackson features, including custom serialisers and deserialisers, creators, views, annotation introspectors, etc.

  • Wraps the MongoDB driver DBCollection, providing most of the original methods, plus strongly typed versions.

  • Gives low level access to advanced MongoDB driver features.

  • Supports querying using objects as templates, and selecting fields to return using objects as templates.

  • Supports mapping ObjectIds to strings and byte arrays, using an @ObjectID annotation.

  • Supports @javax.persistance.Id annotation for marking which property is the id (or just call it _id).

  • Provides interface to building update commands with update modifiers, which supports POJOs which will be serialised by Jackson.

  • Provides terse chained query builders

  • Supports database reference conventions, with convenience methods for fetching references and collections of references in one query.

Reference :

http://mongojack.org/

33 questions
3
votes
1 answer

MongoDriver UUID Support

Im having some issues with mongo driver and the way its inserting UUIDs by default in Java. (Mongo driver version 3.2) UUID("...") => BinData(4, "...") LUUID("...") => BinData(3, "...") legacy UUID in unspecified encoding My UUIDs are being…
WillBroadbent
  • 804
  • 2
  • 8
  • 22
3
votes
1 answer

java.lang.IllegalAccessError When trying to make POJO from MongoDB?

So I am trying use MongoJack together with MongoDB and jackson to access Data from MongoDB and turn it into POJO's. I seem to be struggling even though I am doing it in the simplest possible manner and have basically just copy pasted the mongojack…
pokEarl
  • 41
  • 1
  • 4
3
votes
2 answers

Simple object insertion using MongoDB and MongoJack

I'm trying to follow the MongoJack tutorial but I'm failing the first task: Inserting an object into the database. This is what I have: DB db = new MongoClient().getDB("mydb"); JacksonDBCollection coll = …
aioobe
  • 413,195
  • 112
  • 811
  • 826
2
votes
1 answer

"com.fasterxml.jackson.databind.JsonMappingException: Expected type float, integer, or string." converting the java.time.Instant with ObjectMapper

I am mapping the linkedHashMap to my Custom Pojo class using the below code. ObjectMapper mapper = new ObjectMapper();**mapper.registerModule(new ParameterNamesModule()).registerModule(new Jdk8Module()).registerModule(new JavaTimeModule());**…
Bhagath
  • 63
  • 8
2
votes
1 answer

compare two collections in mongodb using java or an simple query

I am having following document (Json) of an gallery, { "_id": "53698b6092x3875407fefe7c", "status": "active", "colors": [ "red", "green" ], "paintings": [ { …
1
vote
0 answers

MongoJack with Kotlin

I might be asking for trouble with this setup but I am trying to get MongoDB with MongoJack to work with Kotlin classes. I've managed to overcome a few problems already for which I will outline my solutions if others have the same problem but I am…
Ben
  • 1,922
  • 3
  • 23
  • 37
1
vote
1 answer

Mongojack: invalid hexadecimal representation of an ObjectId

Goal I am trying to push some data to a mongo db using mongojack. I expect the result to be something like this in the db: { "_id": "840617013772681266", "messageCount": 69420, "seedCount": 18, "prefix": "f!", "language":…
user11206667
1
vote
0 answers

MongoJack with java.time

Using MongoJack with the libraries at the following versions, I want to store a POJO into Mongo (Azure Mongo API for Cosmos, 3.6) and have a field that uses java.time serialized into a Mongo Date ISODate() format. mongodb-driver-sync…
Dylan Morley
  • 1,656
  • 12
  • 21
1
vote
2 answers

What does <> in Java mean?

Looking at a library called mongojack 3.0 - https://github.com/mongojack/mongojack. This library contains a file called JacksonMongoCollection.java It has a method... public JacksonCollectionKey getCollectionKey() { return new…
barrypicker
  • 9,740
  • 11
  • 65
  • 79
1
vote
1 answer

Mongodb cursor.toArray() is too slow

I am using cursor.toArray() to return my collection.find(query) as a list and response time for my API is in 100's of milliseconds. Data fetched into the cursor is very less (a couple of hundred records), the database is indexed on the field I am…
sudarshan kakumanu
  • 308
  • 1
  • 4
  • 15
1
vote
0 answers

MongoJack MongoDB Scala Optional ObjectId Not Working

Hi I have my case class defined as so case class bread ( @ObjectId @JsonProperty("_id") id: Option[String] = None, @JsonProperty("yeast_level") yeastLevel: Int, @JsonProperty("name") name: String ) My Json looks like this { "id":…
1
vote
1 answer

How to use elemmatch in in mongojack in Java

Given a mongoDB collection containing the following: { "_id" : ObjectId("561c04bde4b05625eaaaf691"), "groupName" : "Group1", "Rights" : [ "RIGHTS_1", "RIGHTS_2" ], "users" : [ "User 1" ]} ,{ "_id" :…
Harry
  • 111
  • 1
  • 8
1
vote
1 answer

MongoJack not finding object

While attempt to work with MongoJack it suddenly started to return null with every findOneById query. Even though the object is being created in the database and the ID returned is valid. Code import com.mongodb.DB; import…
1
vote
1 answer

MongoDB average value of attribute of embedded array (using Java and MongoJack)

I have a collection named "Restaurants" which looks like this: { "_id" : ObjectId("51236fbc3004f02f87c62e8e"), "name" : "Some very fancy name" reviews: [ {"id" : 1, "text" : "saffas" "rating" : 3, …
user238312
  • 41
  • 3
1
vote
0 answers

Test if a node matches a MongoDb query

I would like to test if a Jackson node matches a set of conditions, expressed with MongoDb query operators (or eventually MongoJack's DBQuery objects) Is there an out-of-the-box solution that I've missed, or should I build it myself ? Sample…
Benoît
  • 1,080
  • 11
  • 28
1
2 3