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 ']
mongotest.php, set the user name and password required for the connection, and establish a database connection
$conn = new Mongo ("Mongodb://localhost:27017//admin:admin");The default user and password is adminSelect Database Blog, if not, create$db = $conn->blog;can also be written: $db = $conn->selectdb (' blog ');Develop result set (table name: Posts)$collection = $db->posts;Can also be written as: $collection = $db->selectcollection (' pos
Start MongoDB: sudo service mongodb start ,mongo
After testing, the key can be quoted or not added, but the value is generally quoted, except for the value type
MongoDB is case-sensitive, and naming is usually based on the camel-named method
MongoDB will be created automatically if the database/collect
Tags: base min value val opened result mongod import ISP
Simple query: Use a custom Xxxrepository interface. (See Chapter 11th Springboot + mongodb (simple query))
Complex Queries : Building classes with mongotemplate and some query criteria (basicdblist, basicdbobject, criteria, etc.)
1, Application
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
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
In the past-blogs, the topic mainly focus on the high query operation of MongoDB. In this blog, we simply study the regex expression in the mongdb. MongoDB also support the Regex query. For exampleThe expression is also able to combination with other expression.Notes:/^a/; /^a.*/; /^a.*$/has the same result, however th
({"name": {"$not": {"$in": ["Stephen2", "Stephen1"]}}){"_id": ObjectId ("4fd58ecbb9ac507e96276f1a"), "name": "Stephen", "Age": +, "Genda": "Male", "email": "[email protected]" } 3. Query for the null data type:--When a query with null data is made, all values are null and documents that do not contain the specified key are retrieved. > Db.test.find ({"x": null}){"_id": ObjectId ("4FD59D30B9AC507E96276F1B"
invalid, only the entire database can be synchronizedThis bug1.0.3 does not exist before. It appears after 1.4.0 modification.
CHANGE Part
The incremental synchronization parameter is changed from millisecond to second (All Versions earlier than 1.6.0 are milliseconds );
Improve the incremental synchronization progress display (Other unchanged) in real-time synchronization, remove the progress bar, instead of displaying the oplog lag time.
Recovery parameter -- tu, -- tp, that is, specify
Install slightly. It's a personal metropolis.Here is the connection configuration.The main introduction is to create a set of data through Robomongo to achieve two machine data can be quickly migrated, without the shell command to slowly knock.It is mainly to simplify the process of migrating a single table or a small amount of data.1. Create a new collection test.2. Click the Insert.3. A box appears.4. Go to another machine, find the appropriate data source, right-click All copy5. Paste into th
Recently wanted to do a front-end control Interface field return of a basic method, through the MongoDB find ($query, $field) query to specify the fields of the query, but encountered such a problem:There are two encapsulation methods in the work code:/*** Query a record* @p
This article describes a simple php Tutorial on MongoDB operations, including connection, addition, modification, deletion, and query. For more information, see MongoDB.
The code is as follows:// Connect to localhost: 27017$ Conn = new Mongo ();
// Connect to the default port of the remote host$ Conn = new Mongo ('test. com ');
// Connect to Port 22011 of the
. 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
Previous article, wrote MongoDB General operation, continue to write, this chapter mainly talk about advanced query, text, aggregation, Big Data query.MongoDB has a lot of query syntax and is a richer one in the NoSQL ranks. Of course, there are many queries that cannot be compared with relational queries. For instance, Mongo
In MongoDB, the Db.collection.find () method is used to retrieve documents from the collection. The Db.collection.find () method returns a cursor that retrieves the document. The Db.collection.findOne () method also performs a read operation, returning a document. On the internal implementation, the Db.collection.findOne () method is Db.collection.find () using limit 1.
All documents in the query collectio
First use the official C # access component https://github.com/mongodb/mongo-csharp-driverThen, reference MongoDB after compilation. bson. dll and MongoDB. driver. dll, and declare reference to using MongoDB In the cs file. bson; using MongoDB. driver; using
When $ or and sort () are used in MongoDB, a solution with poor query performance is mentioned in the previous article. when $ or and sort () are used in MongoDB, query performance may be poor. for details, refer to mongodb's plan. this bug may be modified in version 2.5.w. I encountered this problem in my project, and
Tags: solution das Cursor Fetch number implementation collect study ARP formatRecently the project has been using MongoDB as a database, MongoDB has his advantage, the document type JSON format to store data, modified than the traditional relational database more convenient, but recently in MongoDB with the query slow
followed by a parameter, 0 means the display is not displayed in the query Results 1 representsFor example: View only name and gender:Db.stu.find ({},{name:1, gender:1})//_id is displayed by default, if it is not displayed _id need special designation//projection set to 1 except _id other parameters are displayed by defaultdo not show _id:db.stu.find ({},{_id:0,name:1})3.8 Sorts sort ():db. Collection. Find (). sort ({field 1:1, field 2:-1})//Specify
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.