• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieve only particular HashMap entry ( Projection )

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic