资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

MongoDB常用操作-创新互联

关系型数据库名词与MongoDB对比:

创新互联公司是专业的周村网站建设公司,周村接单;提供成都做网站、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行周村网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
关系数据库 MongoDB
Database Database
Table Collection
Row Document
Index Index
Join Lookup
 Foreign KeyReference
Multi-table transaction Single document transaction

命令行使用MongoDB

插入你的第一数据

> show databases

local 0.000GB

> use test  #切换到test数据库,如果没有则新建

 switched to db test

> show databases local 0.000GB

> db.demo.insert( { "key" : "value" } ) WriteResult({ "nInserted" : 1 })

> show databases local 0.000GB test 0.000GB

> show collections demo

> db.demo.findOne() { "_id" : ObjectId("573af7085ee4be80385332a6"), "key" : "value" }

python中使用MongoDB

import pymongo # # client defaults to localhost and port 27017. eg MongoClient('localhost', 27017) client = pymongo.MongoClient() #连接到本地数据库 blogDatabase = client[ "blog" ]      #切换到blog数据库 usersCollection = blogDatabase[ "users" ]     #切换到usersCollection usersCollection.insert_one( { "username" : "jdrumgoole", "password" : "top secret", "lang" : "EN" }) #插入一条数据 user = usersCollection.find_one() #查找最新的一条数据 print( user ) articlesCollection = blogDatabase[ "articles" ] author = "jdrumgoole" article = { "title" : "This is my first post", "body" : "The is the longer body text for my blog post. We can add lots of text here.", "author" : author, "tags" : [ "joe", "general", "Ireland", "admin" ] } # # Lets check if our author exists # if usersCollection.find_one( { "username" : author }) : articlesCollection.insert_one( article ) else: raise ValueError( "Author %s does not exist" % author )

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页标题:MongoDB常用操作-创新互联
文章位置:http://cdkjz.cn/article/cdhhdi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220