1.挿入操作の詳細説明
db.collection.insertOne()は
、複数のドキュメントを挿入します。db.collection.insertMany()
db.inventory.insertMany([
{
item: "journal", qty: 25, size: {
h: 14, w: 21, uom: "cm" }, status: "A" },
{
item: "notebook", qty: 50, size: {
h: 8.5, w: 11, uom: "in" }, status: "A" },
{
item: "paper", qty: 100, size: {
h: 8.5, w: 11, uom: "in" }, status: "D" },
{
item: "planner", qty: 75, size: {
h: 22.85, w: 30, uom: "cm" }, status: "D" },
{
item: "postcard", qty: 45, size: {
h: 10, w: 15.25, uom: "cm" }, status: "A" }
]);
2.詳細なクエリ操作
クエリすべて、db.collection.find()、次と同等:SELECT * FROM table_name
query db.collection.find({key:value})条件に従って、SELECT * FROM table_name WHERE name =?
3.単一のドキュメントdbを更新.collection.updateOne()
複数のドキュメントを更新db.collection.updateMany()
4. ドキュメントdb.collection.replaceOne()を置き換えます。
5.すべてのドキュメントを削除しますdb.collection.deleteMany()
比较操作符"$gt" 、"$gte"、 "$lt"、 "$lte"(分别对应">"、 ">=" 、"<" 、"<=")
$ne 对应 不等于
如:某集合B集合中文档有属性x值为整数,需查找10<x<=30的文档,写法如下:
db.B.find({
"x":{
"$gt":10,"$lte":30}})
$exists 判断文档属性是否存在
db.B.find({
"name":{
"$exists":true}}) --查找属性name存在的文档
db.B.find({
"name":{
"$exists":false}}) --查找属性name不存在的文档