MongoDB目录的bin目录中执行mongod.exe文件
mongod.exe --dbpath C:\Users\HP\Desktop\data\db
执行以下命令将MongoDB服务器作为Windows服务运行:管理权限才能运行下面的命令
mongod.exe 127.0.0.1 yourIPadress --logpath "C:\data\dbConf\mongodb.log" --logappend --dbpath "C:\Users\HP\Desktop\data\db" --port yourPortNumber --serviceName "YourServiceName" --serviceDisplayName "YourServiceName" --install
在mongodb-win32-x86_64-2008plus-3.4.24文件中的bin启动cmd
将mongo.exe拖到cmd运行
启动成功
https://docs.mongoing.com/indexes
https://blog.csdn.net/weixin_43934075/article/details/124732807?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166780856016800182174047%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=166780856016800182174047&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-124732807-null-null.142^v63^control,201^v3^add_ask,213^v1^control&utm_term=smile.ding&spm=1018.2226.3001.4449
https://blog.csdn.net/qq_39045558/article/details/124762034?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166816448016800186571603%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=166816448016800186571603&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-1-124762034-null-null.142^v63^control,201^v3^add_ask,213^v2^t3_control2&utm_term=mongo%E7%BC%BA%E5%A4%B1%E6%9F%A5%E8%AF%A2&spm=1018.2226.3001.4187
https://blog.csdn.net/qq_33801641/article/details/117506944?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166816813816800182121728%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=166816813816800182121728&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-4-117506944-null-null.142^v63^control,201^v3^add_ask,213^v2^t3_control2&utm_term=mongodb%20%E8%BF%94%E5%9B%9Einstock%E4%B8%AD%E5%89%8D%E4%B8%A4%E4%B8%AA%E6%96%87%E6%A1%A3%EF%BC%8C%E4%B8%94%E5%8F%AA%E5%8C%85%E5%90%ABqty%E5%AD%97%E6%AE%B5&spm=1018.2226.3001.4187
https://blog.csdn.net/qq_41853447/article/details/108539155?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166816813816800182136825%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=166816813816800182136825&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-108539155-null-null.142^v63^control,201^v3^add_ask,213^v2^t3_control2&utm_term=mongodb%20%E8%BF%94%E5%9B%9Einstock%E4%B8%AD%E5%89%8D%E4%B8%A4%E4%B8%AA%E6%96%87%E6%A1%A3%EF%BC%8C%E4%B8%94%E5%8F%AA%E5%8C%85%E5%90%ABqty%E5%AD%97%E6%AE%B5&spm=1018.2226.3001.4187
https://blog.csdn.net/weixin_45760274/article/details/123673079?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166823139616800186517876%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=166823139616800186517876&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-5-123673079-null-null.142^v63^control,201^v3^add_ask,213^v2^t3_control2&utm_term=mongodb%E6%89%80%E6%9C%89%E6%96%87%E6%A1%A3%20%20%20qty%E5%80%BC%20%20%E5%A2%9E%E9%95%BF10&spm=1018.2226.3001.4187
https://blog.csdn.net/HeroicLee/article/details/122099510?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166823344516800182155527%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=166823344516800182155527&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-3-122099510-null-null.142^v63^control,201^v3^add_ask,213^v2^t3_control2&utm_term=mongo%E6%89%80%E6%9C%89%E6%96%87%E6%A1%A3%20%20dim_cm%E4%B8%AD%20%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E6%95%B0%E5%AD%97%2020%2C%20%E5%B9%B6%E5%B0%86qty%20%E7%BF%BB%E5%80%8D&spm=1018.2226.3001.4187
https://blog.csdn.net/JineD/article/details/107221842?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166825022516800186542641%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=166825022516800186542641&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-107221842-null-null.142^v63^control,201^v3^add_ask,213^v2^t3_control2&utm_term=mongodb%20%E7%BB%BC%E5%90%88%E6%9F%A5%E8%AF%A2&spm=1018.2226.3001.4187
use a
db.createCollection('A')
db.a.insert({ item: "notebook2", qty: 50, size: { h: 11, w: 11, uom: "in" }, hit:"hit",tags: ["red", "blank", "blue"], dim_cm: [ 14, 21 ],status: "C", hit:null, instock: [ { warehouse: "B", qty: 10 } ]})
db.A.insertMany([ { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, hit:null,status: "A",tags: ["blank", "red"], dim_cm: [ 14, 21 ],instock: [ { warehouse: "A", qty: 5 }, { warehouse: "C", qty: 15 } ] }, { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, people:10,tags: ["red", "blank"], dim_cm: [ 14, 21 ],status: "A" , instock: [ { warehouse: "C", qty: 5 } ]}, { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, tags: ["red", "blank", "plain"], dim_cm: [ 14, 21 ],status: "D", instock: [ { warehouse: "A", qty: 60 }, { warehouse: "B", qty: 15 } ]}, { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, tags: ["blank", "red"], dim_cm: [ 22.85, 30 ], status: "D" , instock: [ { warehouse: "A", qty: 40 }, { warehouse: "B", qty: 5 } ]}, { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, tags: ["blue"], dim_cm: [ 10, 15.25 ], instock: [ { warehouse: "B", qty: 15 }, { warehouse: "C", qty: 35 } ], status: "A" } ])
db.a.find() 或 db.A.find()
db.A.find({"status" : "A"}).pretty()
db.A.find({"qty" :{$gte:75} })
db.A.find({$or:[{"status" :{$ne:"A"}},{"status":{$ne:"C"}}]})
db.A.find({"qty":{$gt:25,$lte:75}})
db.A.find({$or:[{"status" :"B"},{"qty":{$lte:75}}]})
db.A.find( { tags :[ "blue" ]})
db.A.find( { tags :{$all:[ "plain","red" ]}})
db.A.find({dim_cm:{$gte:10,$lt:15}})
db.A.find({"size.uom":"cm"})
db.A.find({hit: {$exists:false}}) //不存在false 存在true
db.A.find({hit:null})
/db.A.find({$and:[{tags:0}:["red"]},{"qty":{$ne:25}}]})
/db.A.find({$or:[{tags:[3]},{"status":{$ne:"A"}}]})
db.A.find({$or:[{"instock.qty":{$gt:10,$lt:20}},{"instock.warehouse":"A"}]})
{instock: {$elemMatch:{$or:[{qty:{$gte:10, $lt:20}},{warehouse:"A"}]} }
二、
/db.A.find().limit(2).skip(2) db.A.find().spik(2)
db.A.find({},{item:1})
/db.A.find({},{"instock":1,"instock.qty":1})
db.A.find().sort({"qty":1,"size.h":-1})
//db.A.find().sort({"qty":1})
//db.A.find().sort({"size.h":-1})
/db.A.find({"instock":{$exists:1}}).sort({"qty":-1})
三、
db.A.updateMany({"status":"A"},{$set:{"field value":"hello=1"}})
db.A.updateMany({},{$inc:{"qty": 10}})
//push的作用就是,如果指定的键已经存在,它会向已有的数组末尾加入一个元素,要是没有就会创建一个新的数组
//db.A.updateMany({},{$push:{dim_cm:20}})
//db.A.updateMany({},{$mul:{"qty":2}})
db.A.updateMany({},{$push:{dim_cm:40},$mul:{"qty":2}})
$addto
//db.A.updateMany({"status":"A"},{$set:{"aa":{}}})
//db.A.updateMany({"aa":{}},{$set:{"aa.k":1}})
db.A.updateMany({"status":"A"},{$set:{"aa":{}},$set:{"aa.k":10}})
四、
db.b.createIndex({qty:1},{name:"qqq"})
db.b.createIndex({status:1,tags:1})
db.b.createIndex({"size.h":1})
db.coll.getIndexes()
db.b.dropIndex("qqq")
db.a.find({"tags":1}).explain()
db.g.createIndex({ name: "text", description: "text" } ,{name:"text1"})
db.g.insert([{ "_id": 1, name: "Java Hut", description: "Coffee and cakes" },
{ "_id": 2, name: "Burger Buns", description: "Gourmet hamburgers" },
{ "_id": 3, name: "Coffee Shop", description: "Just coffee" },
{ "_id": 4, name: "Clothes Clothes Clothes", description: "Discount clothing" },
{ "_id": 5, name: "Java Shopping", description: "The following options are available for text indexes only" }
])
db.g.find({$text:{$search:"Just coffee"}})
db.g.find( { $text: { $search: "java coffee shop" } } )