MongoDB Data Summary

Source: Internet
Author: User

MongoDB is a popular nosql software. It has released versions on Windows Linux Mac platform. After testing, the efficiency is still very good, but the memory consumption is very high because mapviewoffile is used, that is, the hard disk data is mapped directly to the memory, so the entire memory needs to be loaded (http://www.cnblogs.com/daizhj/archive/2011/04/25/mongos_mmap_source_code.html ). Memory monitoring and management are still very important.

Data Summary:

MongoDB downloads: http://www.mongodb.org/display/DOCS/Quickstart

Java DRIVER: https://github.com/mongodb/mongo-java-driver/downloads

10 days in charge of db1_ 2 "http://vdisk.weibo.com/s/7-tgW

"MongoDB the definitive guide.pdf" http://vdisk.weibo.com/s/7AF7f

Other materials:

Http://blog.nosqlfan.com/tags/mongodb
Http://www.cnblogs.com/hoojo/archive/2011/06/02/2068665.html

In-depth understanding of MongoDB, source code analysis: http://www.cnblogs.com/daizhj/category/260889.html

// Appendix: Basic Java operations

Package org. senma. Test. Mongo;

/**
* Copyright (c) 2008 10gen Inc.
*
* Licensed under the Apache license, version 2.0 (the "License ");
* You may not use this file before t in compliance with the license.
* You may obtain a copy of the license
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* Distributed under the license is distributed on an "as is" basis,
* Without warranties or conditions of any kind, either express or implied.
* See the license for the specific language governing permissions and
* Limitations under the license.
*/

Import com. MongoDB. Mongo;
Import com. MongoDB. dbcollection;
Import com. MongoDB. basicdbobject;
Import com. MongoDB. dbobject;
Import com. MongoDB. dbcursor;
Import com. MongoDB. dB;

Import java. util. Set;
Import java. util. List;

Public class quicktour {

Public static void main (string [] ARGs) throws exception {

// Connect to the Local Database Server
Mongo M = new Mongo ();

// Get handle to "mydb"
DB = M. getdb ("mydb ");

// Authenticate-optional
// Boolean auth = dB. Authenticate ("foo", "bar ");

// Get a list of the collections in this database and print them out
Set <string> colls = dB. getcollectionnames ();
For (string S: colls ){
System. Out. println (s );
}

// Get a collection object to work
Dbcollection coll = dB. getcollection ("testcollection ");

// Drop all the data in it
Coll. Drop ();

// Make a document and insert it
Basicdbobject Doc = new basicdbobject ();

Doc. Put ("name", "MongoDB ");
Doc. Put ("type", "Database ");
Doc. Put ("count", 1 );

Basicdbobject info = new basicdbobject ();

Info. Put ("X", 203 );
Info. Put ("Y", 102 );

Doc. Put ("info", Info );

Coll. insert (DOC );

// Get it (since it's the only one in there since we dropped the rest earlier on)
Dbobject mydoc = Coll. findone ();
System. Out. println (mydoc );

// Now, lets add lots of little sort ents to the collection so we can sort e queries and cursors
For (INT I = 0; I <100; I ++ ){
Coll. insert (New basicdbobject (). append ("I", I ));
}
System. Out. println ("Total # of orders ents after inserting 100 small ones (shocould be 101)" + Coll. getcount ());

// Lets get all the documents in the collection and print them out
Dbcursor cur = Coll. Find ();
While (cur. hasnext ()){
System. Out. println (cur. Next ());
}

// Now use a query to get 1 Document out
Basicdbobject query = new basicdbobject ();
Query. Put ("I", 71 );
Cur = Coll. Find (query );

While (cur. hasnext ()){
System. Out. println (cur. Next ());
}

// Now use a range query to get a larger subset
Query = new basicdbobject ();
Query. Put ("I", new basicdbobject ("$ gt", 50); // I. e. Find all where I> 50
Cur = Coll. Find (query );

While (cur. hasnext ()){
System. Out. println (cur. Next ());
}

// Range query with multiple contstraings
Query = new basicdbobject ();
Query. put ("I", new basicdbobject ("$ gt", 20 ). append ("$ LTE", 30); // I. e. 20 <I <= 30
Cur = Coll. Find (query );

While (cur. hasnext ()){
System. Out. println (cur. Next ());
}

// Create an index on the "I" Field
Coll. createindex (New basicdbobject ("I", 1); // create index on "I", ascending

// List the indexes on the Collection
List <dbobject> List = Coll. getindexinfo ();
For (dbobject O: List ){
System. Out. println (O );
}

// See if the last operation had an error
System. Out. println ("last error:" + dB. getlasterror ());

// See if any previous operation had an error
System. Out. println ("previous error:" + dB. getpreviuserror ());

// Force an error
DB. forceerror ();

// See if the last operation had an error
System. Out. println ("last error:" + dB. getlasterror ());

DB. reseterror ();
}
}

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.