windows mangoDB

来源:互联网 发布:tripmode for windows 编辑:程序博客网 时间:2024/05/18 14:24

C:\Program Files\MongoDB\Server\3.4\mongod.cfg

systemLog:
    destination: file
    path: d:\data\log\mongod.log
storage:
    dbPath: d:\data\db


如果磁盘不足,报错:

com.mongodb.MongoSocketReadException: Exception receiving message


以管理员身份,运行cmd.exe

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Windows\system32>sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\Program Files\Mongo
DB\Server\3.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
[SC] CreateService 成功

C:\Windows\system32>
C:\Windows\system32>net start MongoDB
MongoDB 服务正在启动 ........
MongoDB 服务无法启动。

请键入 NET HELPMSG 3523 以获得更多的帮助。

C:\Windows\system32>net start MongoDB
请求的服务已经启动。

请键入 NET HELPMSG 2182 以获得更多的帮助。

C:\Windows\system32>cd C:\Program Files\MongoDB\Server\3.4\bin

C:\Program Files\MongoDB\Server\3.4\bin>mongo

MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-11-30T22:01:41.991+0800 I CONTROL  [initandlisten]
2017-11-30T22:01:41.991+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-11-30T22:01:41.991+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-11-30T22:01:41.991+0800 I CONTROL  [initandlisten]
> db
test
> use atii
switched to db atii
> db.t_at_ticketorder.insertOne( { ordercd:1706162500246,membercd:660014810050 } );
{
        "acknowledged" : true,
        "insertedId" : ObjectId("5a2012b874bfa933011f927d")
}

> db.t_at_ticketorder.find( {} )
{ "_id" : ObjectId("5a2012b874bfa933011f927d"), "ordercd" : 1706162500246, "membercd" : 660014810050 }
>  db.t_at_ticketorder.insertOne( { ordercd:1706162500247,membercd:660014810050 } );
{
        "acknowledged" : true,
        "insertedId" : ObjectId("5a2013c974bfa933011f927e")
}
> db.t_at_ticketorder.insertOne( { ordercd:1706162500248,membercd:660014810051 } );
{
        "acknowledged" : true,
        "insertedId" : ObjectId("5a2013d774bfa933011f927f")
}
> db.t_at_ticketorder.find( { ordercd: 1706162500247 } );
{ "_id" : ObjectId("5a2013c974bfa933011f927e"), "ordercd" : 1706162500247, "membercd" : 660014810050 }

//https://docs.mongodb.com/manual/tutorial/query-documents/ 查询例子