手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:mongodb

mongodb删除索引

在讲今天的内容前,请允许我说几句:what the fuck,再说一句:“你哭著對我說童話裡都是騙人的
前两天说过为了速度我建了索引,虽然给id建了unique的索引,但是数据还是不由分说的插了重复的。好吧。因为数据在unique前就进数据库了。所以。。。我必须要再加上dropDups这个条件。

于是乎,我就先开始删除索引,然后灾难就来了:

b.archive.dropIndex({id:1,unique:true})
{ "errmsg" : "index not found", "ok" : 0 }
> db.archive.dropIndex({"id":1,"unique":true})
{ "errmsg" : "index not found", "ok" : 0 }
> db.archive.dropIndex({"id":1,"unique":true},{name:"id"})
{ "errmsg" : "index not found", "ok" : 0 }
> db.archive.dropIndex({"id":1,"unique":true},{"name":"id"})
{ "errmsg" : "index not found", "ok" : 0 }
> db.archive.dropIndex({category_id:1})
{ "errmsg" : "index not found", "ok" : 0 }
> db.archive.dropIndex({"category_id":1})
{ "errmsg" : "index not found", "ok" : 0 }
> db.archive.dropIndex({"key":{"status":1}})
{ "errmsg" : "index not found", "ok" : 0 }

为什么为什么????
为什么我会这么做?是因为:http://www.mongodb.org/display/DOCS/Indexes
这里面写着:

Dropping Indexes

To delete all indexes on the specified collection:

db.collection.dropIndexes();

To delete a single index:

db.collection.dropIndex({x: 1, y: -1})

Running directly as a command without helper:

// note: command was "deleteIndexes", not "dropIndexes", before MongoDB v1.3.2 // remove index with key pattern {y:1} from collection foo db.runCommand({dropIndexes:'foo', index : {y:1}}) // remove all indexes: db.runCommand({dropIndexes:'foo', index : '*'})

我晕啊。这是肿么了。。。
后来还是神仙和赵拂衣说了一句,试一下dropIndex("xxx"),果然。。。Over了。你说,你这不是忽悠人嘛 ,为了这个,我折腾了一个晚上啊。。。。
害得我当时只能dropIndexes,先删除所有的,再重建索引。。。数据又多,我等了好久好久啊。

Tags: mongo

php header 设置Cache

在手册里,关于header函数的说明是说服务端会输出一系列的头,用firebug也可以看得很清楚
一般来说,我们用header控制的情况不是特别多,毕竟不会主动去改什么:一般也就设置设置编码、跳转、压缩等,不太会过多的干涉。下载的时候也会设置头,黑黑

手册上,我们对于cache都是写着如何设置,以便让代码不被cache:


header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Pragma: no-cache"); // Date in the past

而且在设置的时候还得注意在header前不能有输出,否则header设置无效,但都没有写过,如何给页面设置Cache,虽然我们知道有一些办法,比如 E-TAG之类的。当然也有简单的设置:
比如我们在输出前,对内容进行md5,将它当成e-tag只要没变化,就不会有影响。也有其他的方式:

$seconds_to_cache = 3600;
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts"); header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");

缓存1小时,主要是过期时间得用gmdate来设置,而不是date,这个要注意,其他都差不多。maxage要和expire能够对得上。

不算笔记的笔记。

Tags: header