这是我上学期写的文章,算是教程,最初发在我自己的网站上,其实更应该算作是学习笔记吧,因为有些代码我也得回来看一眼才能想起来。从最基础的 MongoDB 的 Shell 端开始学习,然后学习 Web 开发,然后做了个非常简单的 Demo, 基于 MongoDB, Java, Heroku, Spark 和 AngularJS 的 Web App。因为都是用英文学的,学校里与人交流也是用英文,所以就用英文写了,但我最近写的 Swift 学习的几片文章全是中文的,我知道你们都不爱看英文 :) 但这两篇实在是懒得再翻译成中文了。。。所以对 MongoDB 有兴趣的童鞋就将就看看吧。
Foreword
Sometimes you spend tons and tons of time just looking for one method or function or even one simple syntax, but with no result.
Suddenly, you get the answer, and it is on a very common webpage.
"WTF, this is a fking waste of time! Why can't I find it earlier, instead of suffering so much pain?!"
I don't know. Maybe this is exactly the difficulty that stops most people becoming a good engineer. You know, I am still struggling on this way. However, when I write the post, I am happy.
Now, let's get started with our project.)
Add a MongoDB to your Heroku application
First, we need to add a MongoDB database to your Heroku application. There are two choices, Compose MongoDB and mLab MongoDB. Compose MongoDB has no free plan, whereas mLab has a free plan - sandbox. Here I use Compose MongoDB.
To add a Compose database to your Heroku application (using your console):
$ heroku addons:create mongohq:ssd_1g_elastic
To add a mLab MongoDB (free plan):
$ heroku addons:create mongolab
Use the heroku config command to view your app’s config variables. The URL contains all the MongoDB connection information you will need to connect to your database.
$ heroku config | grep MONGOHQ_URL
Now, you can use the MONGOHQ_URL variable in code and configurations for your driver, depending on the language you app is created in, connecting and authenticating to your MongoDB database hosted with Compose.
Use with Java
==NOTE==: The syntaxes between 2.x and 3.x are very different. If you don't want to waste a lot of time like me, please make it clear what version of mongo-java-driver you are using.
You may know this kind of statement, which is in shell:
$ db.things.find({j: {$ne: 3}, k: {$gt: 10} });
You can implement in the java driver, using embedded DBObjects:
query = new BasicDBObject("j", new BasicDBObject("$ne", 3))
.append("k", new BasicDBObject("$gt", 10));
cursor = coll.find(query);
try {
while(cursor.hasNext()) {
System.out.println(cursor.next());
}
} finally {
cursor.close();
}
Create index list:
//create index,1 for ascending,-1 for descending
coll.createIndex("name"); //Forces creation of an ascending index on a field with the default options.
//get the index list
List list = coll.getIndexInfo();
for (DBObject o : list) {
System.out.println(o);
}
See more methods of DBCollection please refer to this docs. You can also find other index types there.
原文地址:http://www.cnblogs.com/Kavlez/p/4268601.html Enumeration
于Java 1.5增加的enum type...enum type是由一组固定的常量组成的类型,比如四个季节、扑克花色。在出现enum type之前,通常用一组int常量表示枚举类型。比如这样:
public static final int APPLE_FUJI = 0
第二章 Getting Started
1.Hive最大的局限性是什么?一是不支持行级别的增删改(insert, delete, update)二是查询性能非常差(基于Hadoop MapReduce),不适合延迟小的交互式任务三是不支持事务2. Hive MetaStore是干什么的?Hive persists table schemas and other system metadata.
/*
* 0.use a TwoWayLinkedList to store the path.when the node can't be path,you should/can delete it.
* 1.curSum==exceptedSum:if the lastNode is TreeNode,printPath();delete the node otherwise
//js获取项目根路径,如: http://localhost:8083/uimcardprj
function getRootPath(){
//获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
var curWwwPath=window.document.locati
在Linux下面部 署应用的时候,有时候会遇上Socket/File: Can’t open so many files的问题;这个值也会影响服务器的最大并发数,其实Linux是有文件句柄限制的,而且Linux默认不是很高,一般都是1024,生产服务器用 其实很容易就达到这个数量。下面说的是,如何通过正解配置来改正这个系统默认值。因为这个问题是我配置Nginx+php5时遇到了,所以我将这篇归纳进