1.下载mongoDB安装文件:https://www.mongodb.com/download-center?jmp=nav#community
2.安装路径:D://mongodb3.创建数据库文件和log文件-路径为:D://mongodb/date/db和D://mongodb/date/log/mongodb.log4.设置启动服务:D:\mongodb\bin\ cmd mongod.exe --logpath=D:\mongodb\data\log\mongodb.log --dbpath=D:\mongodb\data\db --service5.计算机管理启动服务6.下载mongodb可视化工具http://blog.robomongo.org/robomongo-is-robo-3t/#Download7.链接数据库-创建数据库名称:liushuchen8.eclipse基于spring搭建:mongodb.properties内容:mongodb.replica-set=127.0.0.1\:27017 mongodb.dbname=liushuchenapplicationContent-mongodb.xml内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"><!--org.springframework.data.authentication.UserCredentials <mongo:mongo id="mongo" replica-set="111.13.47.150:27018" /> -->
<mongo:mongo id="mongo" replica-set="${mongodb.replica-set}" /> <mongo:db-factory dbname="${mongodb.dbname}" mongo-ref="mongo" /> <bean id="mappingContext" class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" /> <bean id="mappingMongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> <constructor-arg name="mappingContext" ref="mappingContext" /> <property name="typeMapper" ref="defaultMongoTypeMapper" /> </bean><bean id="defaultMongoTypeMapper" class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
<constructor-arg name="typeKey"> <null /> </constructor-arg> </bean> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> <constructor-arg name="mongoConverter" ref="mappingMongoConverter" /> <property name="writeConcern"> <!-- n 异常 --> <util:constant static-field="com.mongodb.WriteConcern.ACKNOWLEDGED" /> </property> </bean> <!-- 设置用户密码 --> <!-- <bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials"> <constructor-arg name="username" value="ebank" /> <constructor-arg name="password" value="ebank" /> </bean> --></beans>env-mongodb.properties配置:
mongodb.replica-set=127.0.0.1:27017
#mongodb.replica-set=192.168.0.151:27017,192.168.0.152:27017,192.168.0.156:27017mongodb.dbname=liushuchen