Turn from: http://hi.baidu.com/zwfec/item/3cfecfabafda3a258819d38b
Today, look at the server, found that Mongod start not up, prompted
Sun June 2 12:27:02 error:couldn ' t connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
Error
Look up the solution on the Internet, most people say set up dbpath, this is to solve the problem, but not to find the root cause of the problem,
The root of the problem is that the machine illegal shutdown caus
and findAndModify Functions
RunCommand can execute special functions in mongoDB.
FindAndModify is one of the special functions. It is used to return the document after update or remove.
RunCommand ({"findAndModify": "processes ",
Query: {queryer },
Sort {sort },
New: true
Update: {Updater },
Remove: true
}). Value
Ps = db. runCommand ({
"FindAndModify": "persons ",
"Query": {"name": "text "},
"Update": {"$ set": {"email": "1221 "}},
"New": true
}). V
Shell operations on mongodb and shellmongodb
Want to query MongoDB data through shell
Many people on the Internet say that mongoDB does not support shell. I basically agree with this statement;
But the project needs to be done,
Label:The first two days have received a new requirement to monitor the maximum number of MongoDB connections, memory usage, etc. in a Linux shell script.But I do not know about the Linux Shel, but will be some simple common Linux operation, as long as a crazy search, eventually try to finally get these values.The steps for success are as follows:0.writes a row of mongo
Open shell
Start mongod -- dbpath d: \ app \ mongodata on the server first.
Open shell: mongo localhost: 27017
By default, the test user operation is performed. You can use mongo localhost: 27017/admin to increase the permission.
1. Create a database
Use [databaseName]
However, if nothing is done, the empty database will be deleted.
2. view all databases
Show dbs
3. Add a set to the specified database and
Following the previous article, this article is mainly implemented by the C # version of Mongo map-Reduce. If you are not familiar with the C # driver, it doesn't matter. The MongoDB official website has a good getting started article, you will soon learn how to write the Mongo program in C #, instead of entering commands on the console every day. Getting StartedWith the CSHARP driver.
Let's go back to the subject,
II. C # version:
1. construct object
Want to query MongoDB data through the shellMany people on the internet said that MongoDB does not support the shell, this statement I was basically agree;But the project needs, I have to try to do, the key to use--evalIf I want to query the number of users:#cat count_users.sh#! /bin/sh/usr/bin/mongo xxx--quiet--authenticationdatabase admin-u root-p ' xyz '--eval
After running the repair I is able to start the Mongod proccessor and as root, which meant that service mongod start would isn't work. To repair this issue, I needed-make sure, the files inside the database folder were owned and grouped to Mongod . I did this by the following:
Check the file permissions inside your database folder
Note You need to is in your DBPath folder mine is /var/lib/mongo I went tocd /var/lib
I-Ranls -l mongo
This showed me-databases wer
MongoDB has not found a dedicated method to find the maximum value, but can be sorted and take the first one instead.The following collection data is as follows:{"_id": ObjectId ("54c39358acace71b1bd20a70"), "Epoch_min": Numberlong (1422030840), "Usage_ratio": 0.035140007734298706} {"_id": ObjectId ("54c39358acace71b1bd20a71"), "Epoch_min": Numberlong (1422030900), "Usage_ Ratio ": 0.025494230911135674} {" _id ": ObjectId (" 54c39358acace71b1bd20a72 "
: +}]}). Count (); 19. Sort by Salary ascending > Db.mycollection.find (). Sort ({salary:1}); Sort by salary word orderby order 20, descending > Db.mycollection.find (). Sort ({salary:-1}); Sort Descending by Salary field 21. Modify age According to username > db.employee.update ({username: ' jim '},{$set: {age:}},false,true); Db.collection.update (criteria, objnew, Upsert, Multi) Criteria:update query conditions, similar to those in the SQL update queryObjnew:update objects and some updated ope
Tags: io sp strong on Data BS CTI new nbsp/opt/mongodb-2.6.6/bin > MONGO1. Querying all local database names> Show DBS2. Switch to the specified database environment (if no database is specified, create a new library)> Use test;3. Created a collection called ' EMP '> db.createcollection (' emp ');{"OK": 1}4. Query all clustered collections under the current library collection (equivalent to table)> Show Collections;EmpSystem.indexes5. Inserting record
condition of a number of records update all. Writeconcern: Optional, throws an exception level. 4. Example: >db.mongodbtest.update ({' By ': ' Tutorials-itcast '},{$set: {' by ': ' Itcast '}},{multi:true}) 9. MongoDB Delete Document 1. The MongoDB remove () function is used to remove a document from the collection. 2. Grammar The basic syntax of the Remove () method is as follows Db.collection.remove
MongoDBis a NoSQL database, there is no fixed pattern, that is, the same set of different document structure can be different, such as: the first record {name: "Xiaoming"}, the second record: {name: "Xiaoli", age:15}, which is not possible in the relational database. For MongoDB, Where: Collections is the collection of tables that are equivalent to relational databases, and document documents are equivalent to rows in a relational database. So that is
1. Execute the specified statement with the eval parameterFor example, the number of records in the T1 table that needs to query the test library is as follows:[[email protected] bin]#./mongo testMongoDB Shell version:2.6.6Connecting To:test> Db.t1.count ();0>Execute the statement directly from the command line eval parameter:[[email protected] bin]#./mongo test--eval "Printjson (Db.t1.count ())"MongoDB
MongoDB Shell IntroductionMongoDB comes with a JavaScript shell that can interact with the MongoDB real column in the shell using the command line. The shell can perform administrative operations, check for operations such as runn
Label:Recently in the study of MongoDB database, wrote a fully automatic installation of MongoDB database shell script, for reference only, welcome to shoot bricks, the contents are as follows: #!/bin/Bash # Shell execution Options: #-N reads only the shell script, but does
owner of the directory, and then restart MongoDB , start successfully 5 " shown. Figure 5.MongoDB Startup Successabove the way to startMongoDBmode, you need to always open the command line terminal, if you accidentally close it,MongoDBthe process is closed. MongoDBprovides a backgroundDaemonway to start the way we just need to add parameters-Forkand the--logpathcan be.
The MONGO shell is a JavaScript interface used to connect MongoDB, providing users with the means to query and manipulate data in MongoDB, and to manage MongoDB.
start and automatically connect to a MongoDB instance:The default installation in "/usr/bin/", with "which" com
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.