久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

MongoDB常用操作

131次閱讀
沒有評論

共計 1390 個字符,預計需要花費 4 分鐘才能閱讀完成。

自動寫代碼機器人,免費開通

關系型數據庫名詞與 MongoDB 對比:

關系數據庫  MongoDB Database DatabaseTable CollectionRow DocumentIndex IndexJoin Lookup Foreign KeyReferenceMulti-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 )

向 AI 問一下細節

丸趣 TV 網 – 提供最優質的資源集合!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-12-18發表,共計1390字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 乐昌市| 波密县| 新营市| 藁城市| 江陵县| 平泉县| 吐鲁番市| 英超| 仲巴县| 呼伦贝尔市| 宁陕县| 枣阳市| 承德县| 平江县| 元朗区| 桓台县| 沙湾县| 尤溪县| 兴山县| 临桂县| 岑溪市| 绵竹市| 贵阳市| 高阳县| 邯郸县| 仪征市| 芜湖市| 温州市| 吉安县| 奉化市| 定兴县| 安多县| 简阳市| 新建县| 宁晋县| 渝北区| 宿州市| 海兴县| 新丰县| 紫云| 文山县|