MongoDB Installation and Simple commands

Source: Internet
Author: User
Tags modifier


MONGO official website Http://www.mongodb.org/downloads

Vue Tools Download http://www.mongovue.com/downloads/


Build a folder, put the extracted MONGO file, in the new one put the specified database

Make a variable, specify bin

The following folders and paths can be customized

Mongod--dbpath D:\installSoft\mongoDbDATA

MONGO 127.0.0.1:27017/admin


Here is a simple command

Download MongoDB specified path datamongod--dbpath e:\mongoDB\mongoDbDATAmongo 127.0.0.1:27017/adminuse dbname--New database Db.dropdatabase ()--delete show DBS-Show show collections-Display set 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 Data Db.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: "repeat"})--error Db.pp.save ({_id: "repeat"})--Update db.pp.remove ()--Collection Delete Index does not delete db.system.indexes.find () db.pp.remove ({_id:1})--Conditional Delete db.docName.update ({finder},{modifier}) insertorupdate--Default false Db.docName.update ({},{modifier},true)--batch update false update does not save, true Bulk (the first data is only updated by default) db.pp.update ({name: "Hello"},{$set: {name: "Hellowrold"}},false,true)$set $inc--Append the number $unset--Remove the designated Jian $push--Wangga array db.test.update ({_id:1},{$push: {books:["", "" ","]}) Db.test.update ({ _id:1},{$pushAll: {books:["", "", "]}) $addToSet--If the array is not added Db.test.update ({_id:1},{addtoset{books:" hellos " }}) $pop-1 Delete the first value 1 remove the last value 1$pull--Deletes a specified value $pullall db.test.update ({_id:1},{$pullAll: {books:["AA", "BB"]}}) $. In the array pair image, modify Db.test.update ({"Books.type": "DB"},{$set: {"Books.$.author": "Liangrui"})--add some not to join, do not join Db.test.update ({ _id:2},{$addToSet: {books:{$each: ["JS", "DB"]}})--runcommand can only modify one Lou according to whether the new return PP is updated or updated Ps=db.runcommand ({"Findan Dmodify ":" "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 display the number of m between >25 <30 () db.rui.find ({m:{$gte: $lte: 30}},{_id:0,name:1})-- Not equal to Db.rui.find ({name:{$ne: "Hello"}},{})--in in Db.rui.find ({name:{$in: ["Hello"]}},{})--nin not Db.rui.find ({name:{$ nin:["Hello"]}},{})--or C greater than 20 or m greater than 30 of data Db.rui.find ({$or: [{c:{$gt: 20}},{m:{$gt: 30}}]},{})--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})--Take back Db.rui.find ({name:{$not:/ji/i}},{_id:0,name:1})--like JS and Java book student Db.rui.find ({books:{$all: ["JS", "Java "]}},{books:1,_id:0,name:2}"--Query the second C + + student Db.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 to query out the number of books that you like 4 students Db.rui.find ({books:{$size: 3}})-------to check out the students who like the number of bookcase more than 2 db.rui.update ({},{$set: {size:3}}, false,true) Db.rui.find ()--Update sizedb.rui.update ({},{$set: {size:3}},false,true) db.rui.update ({name: "Jim"} at the time of the addition and subtraction of the book) {$push: {books: "C"}, $inc: {size:1}})--Db.rui.find of the book ==5 ({size:4})--query Jim likes the number of books Var jim=db.rui.find ({name: "Jim"}) while (Jim.hasnext ()) {obj=jim.next (); print (obj.books.length)}shell is a JS engine to use the driver package $slice the internal value of the specified array db.rui.find ({name: "    Jim "},{books:{$slice: [1,3]},_id:0})-1 last book Db.rui.find ({name:" Jim "},{books:{$slice: -1},_id:0})--document query Var jim=[{ School: "K", Score: "A"}, {school: "L", Score: "B"}, {SchoOL: "J", Score: "P+"}]db.rui.update ({name: "Jim"},{$set: {school:jim}})--Must be in order, all specified Db.rui.find ({school:{school: "K", Score: "A"}},{_id:0})--optimization Db.rui.find ({"School.score": "A", "School.school": "K"},{_id:0,school:1})--$ Elemmatch Solve order problems and traverse all object queries Db.rui.find ({school:{$elemMatch: {school: "K"}}},{_id:0,school:1}) $where query age greater than 22, like C + +  Student Db.rui.find at K School ({"$where": function () {///each document that gets query results var books=this.books;  Get the School object Var school=this.school in the document;  If the age >=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++) {//is not at K School go to school if (school[j].school== "K") {//return 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.ru I.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})


MongoDB Installation and Simple commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.