I. Software environment (version not required) PHP v5.6 extension: MongoDB nginx v1.11 MongoDB v3.2Note: MongoDB extensions must be installedIi. Connection $client = new Mongoclient ($server, $option);$server variable is a string that describes the server to which you want to connectMongodb://[username:[email protected]]host1[:p ort1][,host2[:p ort2:],...] /dbIt
Inserting more than one test data> for (i=1;i... db.blog.insert ({"title": I, "content": "MongoDB Test article. "," name ":" Liu "+i});... }Db.blog.list.find (). Limit ((). ForEach (function (data) {print ("title:" +data.title);}) Cyclic foreach usageDb.blog.findOne (); Fetch a piece of dataDb.blog.find (); take more than one dataDb.blog.remove (); Delete a data setDb.blog.drop (); Delete tableTo delete a database:1.use dbname2.db.dropdatabase ()=====
stores documents in JSON format, and map is the simplest class in Java that represents this data format. The basicdbobject provided by the MongoDB Java driver is a map (which inherits from linkedhashmap and implements the dbobject interface). It converts the data in the map to the bson format and transmits it to MongoDB
Tags: mongodbIn the last blog, there is three query condition to be described. In the blog, we'll continue to what we had leant in the last blog.1 $mod' $mod ' operation is able-make us-to-do simple mod operation, and is no need to use where sentence.\2. $ne, $in, $nin' $ne ' means not equal.' $in ' is same as key word ' in ' in relationship. $nin is opsitive to ' in '3. $or and $norDurning the mutiple conditions, then result would be is return that i
:" + users.findandmodify ("New Basicdbobject" ("Age", "page"), New Basicdbobject ("name", "ABC")); Print ("findandmodify:" + users.findandmodify ( New Basicdbobject ("Age", 28),//Querying age=28 data New Basicdbobject ("name", true),//Query the Name property New Basicdbobject ("Age", true),//Sort by age False,//Whether Delete, true means delete New Basicdbobject ("name", "ABC"),//modified value, change name
example, querying ageDb.users.find ({age:{$lt: ()}) Db.users.find ({age:{$gt:()})Db.users.find ({age:{$lte:]}) Db.users.find ({age:{$gte:22}})1.3 The logical OR operator is represented using $or, and the format is{$or: [{For example, querying all the user age=21 or age=22Db.users.find ({$or: [{age:21},{age:22}]})1.4, the logic and operator use ",", or $and, the format is{$and: [{For example, the query name is "T1" and all the user age=21Db.users.find
I have been idle for a while recently, and I have been able to spend enough time studying code integration. Because there are too many linguistics, I gradually feel that it is meaningless. I learned a little from other groups using MongoDB. In view of this quick start, because the foundation is not very reliable, it will always be forgotten. Looking at the MongoDB authoritative guide, although it is in Engl
Java code www.2cto. commongoclient?clientnull; try {mongoclientnew?client (102.198.119.29, 27017); dbdb=client. getDB (syslog); set the Where condition Scheme ($ match, newBasicDBOb
Java code www.2cto.com using client = null for MongoDB aggregation query; try {using client = new using client (102.198.119.29, 27017); DB
MongoDB query analysis ensures that our proposed indexes are valid and is an important tool for performance analysis of query statements.MongoDB query analysis commonly used functions are: explain () and hint ().
Using Explain ()Explain operations provide query informa
first document data in the collection, this method returns only one document data,This approach applies to matching only one document at the time of your query, or you only care about the first piece of data
Copy Code code as follows:
$obj = $collection->findone ();
Var_dump ($obj);
?>
You will see the following results
Copy Code code as follows:
Array (5) {
["_id"]=>
Object (mongoid) #6 (0) {
}
[' Name ']
We know that MongoDB is a kind of relational database, so its query method is very different from the standard Structured Query language SQL. But no matter how complicated a structure it is, when it passes through the developer's hands, it only becomes the structure that the customer wants. Today is about how to MongoDB
Thinkphp uses the mongodb database for multi-condition query. One project uses the mongodb database and the query conditions are and or. according to the official Thinkphp manual, use composite query (_ complex) and getLastSql to output
MongoDB BASICS (add, delete, modify, and query)
1. Insert
The insert Statement of MongoDB is in the following format:
db.collection.insert(document)
Document is the document data, and collection is the collection of document data. If the collection exists, the document will be added to the collection directory. If the collection does not exist, the database will
Common query indexes of mongoDB (III)1. _ id index is the default index created by the vast majority of sets. For each inserted data, MongoDB automatically generates a unique _ id field. > Db. jerome_2.collection.insert ({x: 2}) WriteResult ({"nInserted": 1})> db. jerome_2.collection.getIndexes () [{"v": 1, "key": {"_ id": 1}, "name": "_ id _", "ns ": "jerome. je
Today in the project encountered about MongoDB nested query, has not been contacted before, query the relevant data to record the results.
The data in the MongoDB are as follows:
> Db.customer.findOne ()
{
"_id": ObjectId ("57636c8e35defe029962107e"),
"_class": " Com.bu2trip.ticket.model.Customer ",
" name
Detailed examples of PHP operations on MongoDB (add, delete, modify, and query) (6) PHP operations on mongodb:
Modules are required for PHP to operate mongodb.
Official website can download: http://pecl.php.net/package/mongo download
Set mongodb to user-authorized startu
On the blog about MongoDB processing large file ideas and processes, let's look at how the Java driver to implement file operations. The Java driver provided by MongoDB encapsulates specific implementation details, and we are very simple to operate.
Add, delete, and read files by using a few components:
Gridfs: A core
. Database username Password
The database username and password are empty by default after successful startupPHP Mongod Extended installation
Download: http://download.csdn.net/detail/dupingjin/7577217
Select the appropriate extension based on the PHP version, which is used here
Php_mongo-1.4.5-5.5-vc11-nts.dllInto
PHPDirectory
extfolder under
Modify PHP.ini
To increase at the end of a line or php.ini extension.
Extension=php_mongo-1.4.5-5.5-vc11-nts.dllRestart the Php/nginx/apache environme
In MongoDB, you can use the Db.collection.explain ("executionstats") statement to analyze query performance.
Create the table inventory in MongoDB and insert the test data, the initial data in addition to the ID field is not indexed.
{"_id": 1, "item": "F1", type: "Food", quantity:500}
{"_id": 2, "item": "F2", type: "Food", quantity:100}
{"_id": 3, "item": "P1"
Label:In MySQL, the slow query log is often used as the basis for us to optimize the database, is there a similar function in MongoDB? The answer is yes, that's the MongoDB database Profiler. So MongoDB not only has, but also has some more detailed information than the MySQL slow Q
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.