• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve only particular HashMap entry ( Projection )

 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am new to MongoDB. In my document there is one HashMap entry ( projection)
I want to write a query so that it returns me ONLY the HashMap entry ( projection) from a particular document and not the whole document so that I can manipulate the HashMap object in my Java code.

Thanks,
FKA



 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean here - MongoDB stores JSON-style documents, which are not exactly the same as hashmaps.

The MongoDB online manuals contain lots of good advice on how to do different kinds of queries via the MongoDB shell. This might be a good place to start as you can try out your queries directly on the database. It sounds like you simply want to limit the output to specified fields, which is a "projection".

If you are using another language e.g. Java or Python, then the relevant database driver documentation should provide examples of how to construct your query document to achieve your requirements e.g. the MongoDB Java driver documentation includes a quick introduction.

But if I were you I'd start in the shell, so you can concentrate on getting your query right first. Once you know what your query should look like, it will be easier to build the corresponding query in Java or Python. This is a good general approach to building database queries, even on SQL databases, as it means you can focus on getting the query right, before you have to worry about how to make it work via your driver.

I would also recommend you complete one of the free online courses from MongoDB University e.g. M101J MongoDB for Java Developers and M101P MongoDB for Python Developers are both starting again from today. These courses will teach you all the basics about how to work with MongoDB in your chosen language, and they're a great way to get up to speed quickly with this technology.
 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chris!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic