MongoDB文件管理
阿新 • • 發佈:2020-12-06
增
db.collection.save() # 對已有的記錄(_id)進行更新,對沒有的記錄進行插入
db.collection.insert() # 對已有的記錄(_id)不操作,對沒有的記錄進行插入
db.collection.insertOne() # 插入一條
db.collection.insertMany() # 插入多條
查
db.collection.find() # 查所有(20條) db.collection.find({"name": "test"}, {"_id": 0, "name": 1, "age": 1}) # 匹配name的記錄,且只顯示name和age、不顯示_id db.collection.find() # 返回第一條 db.collection.count() # 顯示記錄數 db.collection.find().skip(2) # 跳過前兩條 db.collection.find().limit(3) # 只顯示前三條
改
db.collection.updateOne()
刪
db.collection.deleteOne()