• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert 'raw' mongo projection query to Java JsonObject query

 
Shane Paul
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a mongo query that retrieves two members of one item in an inner array. My query is like this

in pseudo english:

in the collection "people-23-03-15" If the entry has mktid =x and any element of the inner array "actors" has selectId=y then get "selectId" and "address" of that matching inner array element. Working mongo query looks like this:



I have started converting my query to java JsonObject query like this:



I am using this example as my base Create a simpe RESTful service with vert.x 2.0, RxJava and mongoDB, http://www.smartjava.org/content/create-simpe-restful-service-vertx-20-rxjava-and-mongodb
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have a question you wanted to ask about this?
 
Shane Paul
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Apologies if question is not clear, i don;t seem to have option to edit my question now though.

My question is I have the posted working 'raw' mongo query and I cannot convert it to a java style jsonobject query. I included my attempt at the conversion but it does not work...any help to write this query in java using jsonobject would be much appreciated.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I don't use Java with MongoDB, but you might want to check out the samples for the current MongoDB Java driver (thare is also a new Java driver on the way).

Bear in mind that MongoDB does not store data in JSON, but in BSON. Depending what tools you are using to access MongoDB, you may need to implement the conversion between JSON and BSON in your code.
 
Shane Paul
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

the use of Json and Mongo works fine as per the example I posted (vertx and mongo example) and for myself for simpler queries, the issue I have is modifying it to make use of the $elemMatch and projection query functions of a raw mongo query....

Thanks again for the reply...

My latest effort!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic