温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MonGo---安装及其基本操作

发布时间:2020-06-14 05:50:08 来源:网络 阅读:402 作者:woxuewangluo 栏目:MongoDB数据库

1、安装Mongo数据库:

  在发布本文的时间官方提供的最新版本是:1.6.5 ,如果不做特殊声明,本教程所用的版本将会是这个版本。

  1. 第一步:下载安装包:官方下载地址←单击此处,如果是win系统,注意是64位还是32位版本的,请选择正确的版本。

  2. 第二步:新建目录“D:\MongoDB”,解压下载到的安装包,找到bin目录下面全部.exe文件,拷贝到刚创建的目录下。

  3. 第三步:在“D:\MongoDB”目录下新建“data”文件夹,它将会作为数据存放的根文件夹。

 配置Mongo服务端:

  打开CMD窗口,按照如下方式输入命令:
  > d:
  > cd D:\MongoDB
  > mongod --dbpath D:\MongoDB\data

在浏览器输入:http://localhost:27017/,可以看到如下提示:
  You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number

2、基本操作:

创建\使用数据库:

> use mongotest

switched to db mongotest


显示数据表:

> show tables;


插入数据:

> item={"Key":"1","text":"wokao","number":3}

{ "Key" : "1", "text" : "wokao", "number" : 3 }

> db.wang.insert(item)


查询数据:

> db.wang.find();

{ "_id" : ObjectId("52c7812912eae9cca2c31826"), "Key" : "1", "text" : "wokao", "number" : 3 }

> item={"Key":"1","text":"wokao"}

{ "Key" : "1", "text" : "wokao" }

> db.wang.insert(item)

> db.wang.find();

{ "_id" : ObjectId("52c7812912eae9cca2c31826"), "Key" : "1", "text" : "wokao", "number" : 3 }

{ "_id" : ObjectId("52c7814912eae9cca2c31827"), "Key" : "1", "text" : "wokao" }

> show tables;

system.indexes

wang

> db.system.indexes.find();

{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "mongotest.wang", "name" : "_id_" }


数据删除:

> db.wang.remove({ "_id" : ObjectId("52c7812912eae9cca2c31826")})

> db.wang.find();

{ "_id" : ObjectId("52c7814912eae9cca2c31827"), "Key" : "1", "text" : "wokao" }


数据修改:

> db.wang.find();

{ "_id" : ObjectId("52c7814912eae9cca2c31827"), "Key" : "1", "text" : "wokao" }

> var t=db.wang.findone({"Key" : "1"})

Sat Jan 04 11:42:29.671 TypeError: Property 'findone' of object mongotest.wang is not a function

> var t=db.wang.findOne({"Key" : "1"})

> t.text="wo shi ni yeye!!"

wo shi ni yeye!!

> db.wang.update({"Key" : "1"},t)

> db.wang.find();

{ "_id" : ObjectId("52c7814912eae9cca2c31827"), "Key" : "1", "text" : "wo shi ni yeye!!" }


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI