MongoDB operation: Update ()

Source: Internet
Author: User

  1. @Override
  2. public boolean update (string dbName, String CollectionName,
  3. DBObject OldValue, DBObject newvalue) {
  4. DB db = null;
  5. Dbcollection dbcollection = null;
  6. Writeresult result = null;
  7. String resultstring = null;
  8. if (Oldvalue.equals (NewValue)) {
  9. return true;
  10. }else{
  11. try {
  12. db = Mongoclient.getdb (dbName); Get DB Instance
  13. Dbcollection = Db.getcollection (CollectionName); Gets the specified collection collection in the database
  14. result = Dbcollection.update (OldValue, newvalue);
  15. resultstring = Result.geterror ();
  16. Return (resultstring!=null)? False:true;
  17. } catch (Exception e) {
  18. Todo:handle exception
  19. E.printstacktrace ();
  20. } finally{
  21. if (null! = db) {
  22. Db.requestdone (); Turn off DB
  23. db = null;
  24. }
  25. }
  26. }
  27. return false;
  28. }

MongoDB operation: Update ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.