Home > Database > Mysql Tutorial > MongoDB数据库设置初始化脚本

MongoDB数据库设置初始化脚本

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:35:30
Original
1626 people have browsed it

很多时候,我们需要初始化数据库的设置,比如创建索引,特别是多台MongoDB服务器要配置的时候,或者是需要将初始化存档的时候。

很多时候,我们需要初始化数据库的设置,比如创建索引,特别是多台MongoDB服务器要配置的时候,或者是需要将初始化存档的时候。

通过下面的命令,可以执行一个js文件:

./mongo IP/DBName init.js

init.js文件内容可以这么写:

db.dropDatabase(); //删除数据库达到清空数据的目的

db.message.ensureIndex({display_id:1}); //在当前数据库中的message集合的display_id字段上创建索引

这里很奇怪,,数据库被删除了也能够创建索引,但是的确可以这么用。

以后当程序连接该数据库的时候,如果没有MongoDB会创建该数据库。集合也是如此。

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

相关阅读:

MongoDB备份与恢复

CentOS编译安装MongoDB

CentOS 编译安装 MongoDB与mongoDB的php扩展

CentOS 6 使用 yum 安装MongoDB及服务器端配置

Ubuntu 13.04下安装MongoDB2.4.3

如何在MongoDB中建立新数据库和集合

MongoDB入门必读(概念与实战并重)

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

linux

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template