zoukankan      html  css  js  c++  java
  • mongoDB学习笔记一

    Windows上安装mongoDB

    下载地址:https://www.mongodb.org/downloads

    双击安装-->next-->next-->custom-->设置安装目录(h:MongoDB)

    运行mongonDB,根目录下创建datadb目录

    Cmd 进入安装根目录,执行如下命令

    mongod.exe --dbpath h:MongoDBdata

    出现如下错误:

    exception in initAndListen: 28663 Cannot start server. The default  is not available with this build of mongod. Please specify a different storage engine explicitly, e.g. --storageEngine=mma

    执行如下命令:

    mongod.exe --dbpath h:MongoDBdata --storageEngine=mmapv1

    看到如下结果:

    H:MongoDBServer3.2in>mongod.exe --dbpath h:MongoDBdata --storageEngine=mmapv1

    2016-11-20T09:08:10.655+0800 I CONTROL  [main]

    2016-11-20T09:08:10.655+0800 W CONTROL  [main] 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.

    2016-11-20T09:08:10.655+0800 I CONTROL  [main]

    2016-11-20T09:08:10.671+0800 I CONTROL  [main] Hotfix KB2731284 or later update is not installed, will zero-out data files

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten] MongoDB starting : pid=6232 port=27017 dbpath=h:MongoDBdata 32-bit host=retacn

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten] targetMinOS: Windows Vista/Windows Server 2008

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten] db version v3.2.10

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten] git version: 79d9b3ab5ce20f51c272b4411202710a082d0317

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten] allocator: tcmalloc

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten] modules: none

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten] build environment:

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten]     distarch: i386

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten]     target_arch: i386

    2016-11-20T09:08:10.671+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "h:MongoDBdata", engine: "mmapv1" } }

    2016-11-20T09:08:10.777+0800 I CONTROL  [initandlisten]

    2016-11-20T09:08:10.777+0800 I CONTROL  [initandlisten] ** WARNING: This 32-bit MongoDB binary is deprecated

    2016-11-20T09:08:10.778+0800 I CONTROL  [initandlisten] ** NOTE: This is a 32-bit MongoDB binary running on a 64-bit operating

    2016-11-20T09:08:10.778+0800 I CONTROL  [initandlisten] **      system. Switch to a 64-bit build of MongoDB to

    2016-11-20T09:08:10.779+0800 I CONTROL  [initandlisten] **      support larger databases.

    2016-11-20T09:08:10.779+0800 I CONTROL  [initandlisten]

    2016-11-20T09:08:10.779+0800 I CONTROL  [initandlisten]

    2016-11-20T09:08:10.780+0800 I CONTROL  [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.

    2016-11-20T09:08:10.780+0800 I CONTROL  [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).

    2016-11-20T09:08:10.780+0800 I CONTROL  [initandlisten] **       Note that journaling defaults to off for 32 bit and is currently off.

    2016-11-20T09:08:10.782+0800 I CONTROL  [initandlisten] **       See http://dochub.mongodb.org/core/32bit

    2016-11-20T09:08:10.784+0800 I CONTROL  [initandlisten]

    2016-11-20T09:08:10.790+0800 I INDEX    [initandlisten] allocating new ns file h:MongoDBdatalocal.ns, filling with zeroes...

    2016-11-20T09:08:11.211+0800 I STORAGE  [FileAllocator] allocating new datafile h:MongoDBdatalocal.0, filling with zeroes...

    2016-11-20T09:08:11.213+0800 I STORAGE  [FileAllocator] creating directory h:MongoDBdata\_tmp

    2016-11-20T09:08:11.573+0800 I STORAGE  [FileAllocator] done allocating datafile h:MongoDBdatalocal.0, size: 64MB,  took 0.356 secs

    2016-11-20T09:08:11.577+0800 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker

    2016-11-20T09:08:11.577+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'h:/MongoDB/data/diagnostic.data

    '

    2016-11-20T09:08:11.583+0800 I NETWORK  [initandlisten] waiting for connections on port 27017

    MongoDB的默认使用27017端口

    重新启动一个mongoDB,运行mongo.exe

    H:MongoDBin>mongo.exe

    2016-11-20T09:31:58.985+0800 I CONTROL  [main] Hotfix KB2731284 or later update is not installed, will zero-out data files

    MongoDB shell version: 3.2.11

    connecting to: test

    #插入两件记录

    > db.foo.insert({test:1})

    WriteResult({ "nInserted" : 1 })

    > db.foo.insert({test:2})

    WriteResult({ "nInserted" : 1 })

    #查询记录

    > db.foo.find()

    { "_id" : ObjectId("5830fd65465a96c3b983ef1d"), "test" : 1 }

    { "_id" : ObjectId("5830fd6d465a96c3b983ef1e"), "test" : 2 }

    #移除一条记录

    > db.foo.remove({test:1})

    WriteResult({ "nRemoved" : 1 })

    #查询记录

    > db.foo.find()

    { "_id" : ObjectId("5830fd6d465a96c3b983ef1e"), "test" : 2 }

    创建mongoDB服务

    方法一:

    Cmd-->ctrl+shiift+enter(以管理员身份运行)

    创建数据和日志服务

    创建配置文件

    H:MongoDB>mkdir h:MongoDBdatadb

    H:MongoDB>mkdir h:MongoDBdatalog

    创建配置文件

    根目录下创建mongod.cfg文件,添加如下内容:

    systemLog:

        destination: file

        path: H:MongoDBdatalogmongod.txt

    storage:

        dbPath: H:MongoDBdatadb

    安装服务

    mongod.exe --config h:MongoDBmongod.cfg --install --serviceName MongoDB

    第二种方法

    sc.exe create MongoDB binPath= ""h:MongoDBinmongod.exe" --service --config="h:MongoDBmongod.cfg"" DisplayName= "MongoDB" start= "auto"

    开启服务

    Net start MondoDB

    关闭服务

    Net stop MonDB

    删除服务

    方式一:

    mongod.exe --remove  

    方式二:

    sc.exe delete MongoDB


  • 相关阅读:
    HDU6470 ()矩阵快速幂
    O(1)乘法与快速乘O(log)
    imos 学习笔记五 抓拍 c#
    imos 学习笔记四 录像 c#
    imos 学习笔记三 下载指定时间段视频信息 c#
    imos学习笔记二 用户登录c#
    imos学习笔记一 sdk开发环境
    Hbase(nosql)体系结构有基本操作 笔记八
    zookeeper的安装与配置 笔记七
    mapReduce体系结构和各种算法 笔记六
  • 原文地址:https://www.cnblogs.com/retacn-yue/p/6194173.html
Copyright © 2011-2022 走看看