In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you what are the differences between CouchDB and MongoDB in the query operation, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
CouchDB, like MongoDB, is a document store, and they are similar in many ways. To put it simply, the query of MongoDB is a dynamic query, which can query any specified conditions on the existing data. Of course, in order to make our query faster, we need a reasonable design index.
What are the differences between CouchDB and MongoDB in query operation
MongoDB and CouchDB are both document-oriented databases, they both use the JSON document format, they are usually regarded as NoSQL databases, and now both are fashionable and have a lot in common, but when it comes to queries, the difference between the two is obvious. CouchDB requires predefined views (essentially JavaScriptMapReduce functions), while MongoDB supports dynamic queries (basically similar to ad hoc queries on traditional relational databases) and, more importantly, When it comes to queries, CouchDB's API is RESTful, while MongoDB's API is more primitive, which means that a driver is used to issue a query in the code.
For example, when using CouchDB, to insert some data, you can use some external tools, such as Groovy's RESTClient:
Importstaticgroovyx.net.http.ContentType.JSON
Importgroovyx.net.http.RESTClient
Defclient=newRESTClient ("http://localhost:5498/")"
Response=client.put (path: "parking_tickets/1234334325"
ContentType:JSON
RequestContentType:JSON
Body: [officer: "RobertGrey"
Location: "199CastleDr"
Vehicle_plate: "NewYork77777"
Offense: "Parkedinnoparkingzone"
Date: "2010-07-31"])
Note that in this case, I must specify a number (1234334325) for the ticket, and by the way, I can also ask CouchDB to use UUID, such as a HTTPGET request to the / _ uuids path.
For example, if I want to find all the tickets issued by OfficerGrey, I must define a view, which is a simple URL that executes the JavaScriptMapReduce function, so I can quickly implement a function to extract all documents whose officer attribute is equal to RobertGrey.
Function (doc) {
If (doc.officer== "RobertGrey") {
Emit (null,doc)
}
}
I have to give this view a name, and when I make a HTTPGET request to this view, I can get at least one document.
Response=client.get (path: "parking_tickets/_view/by_name/officer_grey"
ContentType:JSON,requestContentType:JSON)
Assertresponse.data.total_rows==1
Response.data.rows.each {
Assertit.value.officer== "RobertGrey"
}
What are the differences between CouchDB and MongoDB in query operation
In general, when using CouchDB, I can't quickly issue an ad hoc RESTful call to query information. I must first define a query (also known as a view) and then expose it. In contrast, when using MongoDB, it is not much different from most relational databases, and you can query any information you want at run time.
For example, here is an example of a parking ticket that I implemented using MongoDB's native Java driver:
DBCollectioncoll=db.getCollection ("parking_tickets")
BasicDBObjectdoc=newBasicDBObject ()
Doc.put ("officer", "RobertGrey")
Doc.put ("location", "199CastleDr")
Doc.put ("vehicle_plate", "NewYork77777")
/ /...
Coll.insert (doc)
Suppose I want to query the parking ticket issued by RobertSmith in the future, I just need to simply modify the value of the officer attribute, such as:
BasicDBObjectquery=newBasicDBObject ()
Query.put ("officer", "RobertSmith")
DBCursorcur=coll.find (query)
While (cur.hasNext ()) {
System.out.println (cur.next ())
}
Although there are many similarities between MongoDB and CouchDB, there are essential differences in query. CouchDB needs to use MapReduce, while MongoDB is more dynamic-oriented. Of course, MongoDB also supports MapReduce.
What is the difference between CouchDB and MongoDB in query operation? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.