jongo

Using Jongo and Jackson 2, how to deserialize a MongoDB ObjectId (represented under String _id in a POJO) to an hexadecimal String representation?

孤街浪徒 提交于 2021-02-07 08:43:47
问题 I use the latest version of MongoDB database and the latest version of the official JAVA MongoDB driver. The dependencies that I use in my pom.xml: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> ... <jersey.container.version>2.13</jersey.container.version> <jackson.version>2.4.3</jackson.version> <genson.version>1.1</genson.version> <jongo.version>1.1</jongo

Using Jongo and Jackson 2, how to deserialize a MongoDB ObjectId (represented under String _id in a POJO) to an hexadecimal String representation?

旧时模样 提交于 2021-02-07 08:43:23
问题 I use the latest version of MongoDB database and the latest version of the official JAVA MongoDB driver. The dependencies that I use in my pom.xml: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> ... <jersey.container.version>2.13</jersey.container.version> <jackson.version>2.4.3</jackson.version> <genson.version>1.1</genson.version> <jongo.version>1.1</jongo

How to serialize ObjectId to JSON?

試著忘記壹切 提交于 2020-01-01 19:52:08
问题 I want to serialize ObjectId of my Product class to JSON. I got the following JSON: [{"name":"Play for Java: Covers Play 2","type":"Book","company":"Manning Publications","price":30.0,"imagePath":"public/images/play-for-java.png","rating":4.5,"category":"Computer","author":"Nicolas Leroux","publicationDate":1396224000000,"numPage":320,"_id":539da7a6370882f10d5c2777}] You can notice that the "_id" didn't be properly serialized, it should be "539da7a6370882f10d5c2777" (with double quotes) and

如何用“ like”查询MongoDB?

混江龙づ霸主 提交于 2019-12-25 09:42:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我想查询一些与SQL的 like 查询: SELECT * FROM users WHERE name LIKE '%m%' 我如何在MongoDB中实现相同目标? 我在 文档中 找不到 like 的运算符。 #1楼 在 使用 Python的 PyMongo 猫鼬 使用 Node.js Jongo ,使用 Java MGO, 用 围棋 你可以做: db.users.find({'name': {'$regex': 'sometext'}}) #2楼 您可以使用where语句来构建任何JS脚本: db.myCollection.find( { $where: "this.name.toLowerCase().indexOf('m') >= 0" } ); 参考: http : //docs.mongodb.org/manual/reference/operator/where/ #3楼 如果使用 node.js , 则 表示您可以编写以下代码: db.collection.find( { field: /acme.*corp/i } ); //or db.collection.find( { field: { $regex: 'acme.*corp', $options: 'i' } } ); 另外

How to do upsert using jongo?

吃可爱长大的小学妹 提交于 2019-12-23 04:06:30
问题 I have a users table/collection and would like to upsert a user - update a user if exists or add a new one if still not exists. Structure below. By "exists", I mean having some external ID. In this case, googleId . How can I do it using Jongo library? Thanks. public class User { public String _id; public String email; public String givenName; public String familyName; public String googleId; } 回答1: Considering having a user with an already loaded googleId (passed google auth), and I'd like to

Manual references support

半腔热情 提交于 2019-12-13 19:05:20
问题 Consider the class: class Person { String name; Person father; Person mother; List<Person> children; } Is there a way to indicate to jongo that father , mother and children should be manual references to other objects within the same collection instead of embedded objects? Note: this is different from DBRefs. 回答1: Not yet. The easiest way is to issue a second query manually. Nevertheless, you can propably create a Jackson de/serializer to fetch documents during unmarshalling process. Few

Regular Expression to find string starts with letter and ends with slash /

梦想的初衷 提交于 2019-12-12 02:08:07
问题 I'm having a collection which has 1000 records has a string column. I'm using Jongo API for querying mongodb. I need to find the matching records where column string starts with letter "AB" and ends with slash "/" Need help on the query to query to select the same. Thanks. 回答1: I'm going to assume you know how to query using Regular Expressions in Jongo API and are just looking for the necessary regex to do so? If so, this regex will find any string that begins 'AB' (case sensitive), is

How to do upsert using jongo?

那年仲夏 提交于 2019-12-08 15:14:35
I have a users table/collection and would like to upsert a user - update a user if exists or add a new one if still not exists. Structure below. By "exists", I mean having some external ID. In this case, googleId . How can I do it using Jongo library? Thanks. public class User { public String _id; public String email; public String givenName; public String familyName; public String googleId; } Considering having a user with an already loaded googleId (passed google auth), and I'd like to upsert it to mongoDB, using Jongo: // Init MongoClient mongoClient = new MongoClient("localhost", 27017);

Mongo Java drivers & mappers performances

一笑奈何 提交于 2019-12-07 08:38:39
问题 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? 回答1: 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

In Jongo, how to find multiple documents from Mongodb by a list of IDs

蹲街弑〆低调 提交于 2019-12-06 07:04:21
问题 In mongodb, I can do this by the following query: find( { _id : { $in : [ ObjectId('5275c6721a88939923c3ea54'), ObjectId('5275c6721a88939923c3ea55'), ObjectId('5275c6721a88939923c3ea56'), ObjectId('5275c6721a88939923c3ea57'), ObjectId('5275c6721a88939923c3ea58') ] } } ) But how can we do the same using Jongo code? I know we can find one document via: db.getCollection("mongoEg").findOne(Oid.withOid("5194d46bdda2de09c656b64b")).as(MongoTest.class); But how to get more than one documents in one