MongoDB installation and simple commands, mongodb installation commands
Mongo http://www.mongodb.org/downloads
Vue tool download http://www.mongovue.com/downloads/
Create a folder and put the unzipped mongo file.
Make a variable and specify the bin
The following folders and paths can be customized.
Mongod -- dbpath d: \ installSoft \ mongoDbDATA
Mongo 127.0.0.1: 27017/admin
The following is a simple command
Download the specified mongodb path datamongod -- dbpath e: \ mongoDB \ mongoDbDATAmongo 127.0.0.1: 27017/adminuse dbname -- create a database db. dropDatabase () -- delete show dbs -- show collections -- display the collection db. persons. insert ({name: "hello"}) -- insert data db. persons. find () db. persons. update ({name: "hello" },{$ set: {name: "newh" }}) var p = db. persons. findOne () pdb. persons. update (p, {name: "updateV"}) db. persons. update ({name: "updateV" },{$ set: {age: 1, name: "newV" }}) db. persons. remove ({age: 1}) -- delete the database. persons. drop () -- delete personsdb. help () function insertxx (obj) {db. getCollection ("dbName "). text. insert (obj)} insertxx ({name: "hello"}) db. getCollection ("dbName "). find () db. eval ("return 'mongodb '") for (var I = 0; I <10; I ++) {db. pp. insert ({name: I})} db. pp. insert ({_ id: "DUPLICATE"}) -- error db. pp. save ({_ id: "DUPLICATE"}) -- Update db. pp. remove () -- the database is not deleted when the index is deleted from the set. system. indexes. find () db. pp. remove ({_ id: 1}) --condition Delete db.doc Name. update ({queryer}, {modifier}) insertOrUpdate -- default value: false db.doc Name. update ({queryer}, {modifier}, true) -- batch update: false. update Is Not saved. true: Batch update: db. pp. update ({name: "hello" },{$ set: {name: "helloWrold" }}, false, true) $ set $ inc -- append a number $ unset -- remove the specified key $ push -- Wang Jia array db. test. update ({_ id: 1 },{$ push: {books: ["01", "02", "03"]}) db. test. update ({_ id: 1 },{$ pushAll: {books: ["01", "02", "03"]}) $ addToSet -- if the database is not added to the array. test. update ({_ id: 1 },{ addToSet {books: "hellos "}}) $ pop-1 Delete the first value 1 Delete the last value 1 $ pull -- delete a specified value $ pullAll db. test. update ({_ id: 1 },{$ pullAll: {books: ["aa", "bb"]}) $. modify db in array objects. test. update ({"books. type ":" db "}, {$ set: {" books. $. author ":" liangrui "}) -- adds some to the database. test. update ({_ id: 2 },{$ addToSet: {books :{$ each: ["js", "db"] }}}) -- runCommand can only modify one data record. new indicates whether pp is before update or ps = db after update. runCommand ({"findAndModify": "test", "query": {"name": "hello"}, "update": {"$ set": {"age ": "wwww" }}, "new": true}) ps. valuedb. rui. find ({},{ _ id: 0, name: 1}) -- query the specified column {condition} {display} 0 does not show the number of m between> 25 <30 () db. rui. find ({m: {$ gte: 25, $ lte: 30 },{ _ id: 0, name: 1}) -- not equal to db. rui. find ({name: {$ ne: "hello" }},{}) -- in the database. rui. find ({name: {$ in: ["hello"] },{}) -- nin is not in the db. rui. find ({name: {$ nin: ["hello"] }},{}) -- or c is greater than 20 or m is greater than 30 data db. rui. find ({$ or: [{c: {$ gt: 20 },{ m: {$ gt: 30}] },{}) -- the query is null db. rui. find ({sex: {$ in: [null] },{ _ id: 0, name: 1, sex: 2}) -- Regular query db. rui. find ({name:/ji/I}, {_ id: 0, name: 1}) -- return to db. rui. find ({name: {$ not:/ji/I}, {_ id: 0, name: 1}) -- A student db who likes js and java books. rui. find ({books :{$ all: ["js", "java"] },{ books: 1, _ id: 0, name: 2 }) -- query the student database of c ++. rui. find ({"books.1": "c ++"}, {books: 1, _ id: 0, name: 2 }) -- query the specified length array $ size. It cannot be used with the comparison query operator to query the number of favorite books that are 4 student DBS. rui. find ({books: {$ size: 3}) -- query the student databases with the number of favorite book boxes greater than 2. rui. update ({},{ $ set: {size: 3 }}, false, true) db. rui. find () -- Update sizedb when adding or subtracting books for the first time. rui. update ({},{ $ set: {size: 3 }}, false, true) db. rui. update ({name: "jim" },{$ push: {books: "c" },$ inc: {size: 1}) -- database of books = 5. rui. find ({size: 4}) -- query the number of books jim likes var jim = db. rui. find ({name: "jim"}) while (jim. hasNext () {obj = jim. next (); print (obj. books. length)} shell is a js engine. Use the driver package $ slice to specify the internal value of the array db. rui. find ({name: "jim"}, {books: {$ slice: [1, 3]}, _ id: 0})-1 db of the last book. rui. find ({name: "jim" },{ books: {$ slice:-1}, _ id: 0}) -- query the var jim = [{school: "k", score: "a" },{ school: "l", score: "B" },{ school: "j", score: "p +"}] db. rui. update ({name: "jim"}, {$ set: {school: jim}) -- all databases must be in the same order. rui. find ({school: "k", score: "a" }}, {_ id: 0}) -- Optimize the database. rui. find ({"school. score ":" a "," school. school ":" k "},{ _ id: 0, school: 1}) -- $ elemMatch solves the sequence problem and traverses all objects to query the database. rui. find ({school :{$ elemMatch: {school: "k" }}, {_ id: 0, school: 1}) $ where query age greater than 22, I like the student db that c ++ has spent in k schools. rui. find ({"$ where": function () {// var books = this. books; // get the school object var school = this in the document. school; // if the age is greater than or equal to 22 if (this. age> 22) {var cjj = null; // traverse data for (var I = 0; I <books. length; I ++) {if (books [I] = "c ++") {cjj = books [I]; // if the school is true if (school) {for (var j = 0; j <school. length; j ++) {// do you want to go to school if (school [j]. school = "k") {// returns true return true ;}} break ;}}}}) --- paging db. rui. find ({}, {_ id: 0, name: 1 }). limit (5) db. rui. find ({}, {_ id: 0, name: 1 }). limit (5 ). skip (5) db. rui. find ({}, {_ id: 0, name: 1, age: 2 }). limit (5 ). skip (5 ). sort ({age: 1}) db. rui. find ({}, {_ id: 0, name: 1, age: 2 }). limit (5 ). skip (5 ). sort ({name:-1 })