MongoDB Database __ Database

Source: Internet
Author: User
Tags json mongodb
Package com;
Import java.net.UnknownHostException;
Import Com.mongodb.DB;
Import com.mongodb.DBCollection;
Import Com.mongodb.DBCursor;
Import Com.mongodb.Mongo;
Import com.mongodb.MongoException;

Import Com.mongodb.util.JSON; /** * <B>FUNCTION:</B>MONGODB Administrative Enday Spells an example * * @author Hoojo * @createDate 2011-5-24 Juan Example 崍 02:42:29 * @file Simpl
 Etest.java * @package com.hoo.test * @project MongoDB * @blog Http://blog.csdn.net/IBM_hoojo * @email hoojo_@126.com
	 * @version 1.0 */public class SimpleTest {/* * public static void Main (string[] args) throws Unknownhostexception, * Mongoexception {Mongo mg = new Mongo ();//Motai ヨ gallium? have fermium 凞 atabase for (String name *: Mg.getdatabasenames ()) {System.out.
	 println ("DbName:" + name);} * * DB db = Mg.getdb ("test");
	 Motai ヨ gallium? Have fermium cancel Flo boss 嗛 泦 Å? for (String name: * Db.getcollectionnames ()) {System.out.println ("CollectionName:" + name);
	 *} * * Dbcollection users = db.getcollection ("users"); * *//Motai ヨ gallium? Have Fermium ecf 暟 is? Dbcursor cur = Users. find (); while (Cur.hasnext ()) {* SYSTEM.OUT.PRINTLN (Cur.next ());}
	 System.out.println (Cur.count ());
	 * SYSTEM.OUT.PRINTLN (Cur.getcursorid ()); * SYSTEM.OUT.PRINTLN (json.serialize (cur));
	        } */public static void main (string[] args) throws Exception {Mongo mg = new Mongo ();
	        Query all database for (String name:mg.getDatabaseNames ()) {System.out.println ("DbName:" + name);
	        } DB db = Mg.getdb ("test"); Queries all clustered collections for (String Name:db.getCollectionNames ()) {System.out.println ("CollectionName:" + NA
	        ME);
	        
	        } dbcollection users = Db.getcollection ("users");
	        Query all data dbcursor cur = users.find ();
	        while (Cur.hasnext ()) {System.out.println (Cur.next ());
	        } System.out.println (Cur.count ());
	        System.out.println (Cur.getcursorid ());
	System.out.println (json.serialize (cur)); }

}

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.