Monday, July 14, 2014

MongoDB Limiting Fields Returned With Java API

Use the "public DBCursor find(DBObject ref, DBObject keys)" in the DBCollection class:
  • For the "keys", add a key value pair like the following to include a field e.g. "name":
    • key: name
    • value: 1
  • _id is always included by default
  • But if _id is all you want, you should include it in keys, otherwise with an empty "keys" object all fields will be returned

No comments:

Post a Comment