Mongodb Study Notes 2 (simple addition, deletion, query, and modification) 1. add a piece of data. I also practiced it yesterday, and today it is further consolidated. There are two main methods: save and insert. Example: db. blog. save ({"name": "taotao", "address": {"city": "beijing", "post": "100096"}, "phone ": "64645646"}) or db. blog. insert ({"name": "taotao", "address": {"city": "beijing", "post": "
Label:Index this thing everyone will not be unfamiliar, as long as the contact to a slightly larger data, will use this thing, it can improve the speed of queries, a considerable price is to occupy more storage space, which is normal, in line with the "energy conservation constant", haha! Today is the index of MongoDB, in my 5 million data query test, I found that if your
Tags: transcode user customer Data Code pos post down stringNot much to say directly on the codeConst HTTP = require (' http '); const DB = require (' MongoDB '). Db;const Connection = require (' MongoDB '). Connection;const Server = require (' MongoDB '). Server;const Query2 = require (' querystring '); var url=require (' url '); let settings = {cookiesecret: '
Label:Go on to the next chapter and continue to introduce MONGODB queries. Querying on Embedded DocumentsThere are two ways to query embedded sub documents: Querying the entire document or querying individual key-value pairs. Querying the entire child document is the same as the normal query. We have a document: {
"name": {
"first": "Joe",
Mongodb entry-7 query 2 array query $ all $ in $ all the elements of all Given Queries must be included in the array $ in. The following two codes can be viewed as long as the given query elements are included in the array.: [html] db. phone. find () {_ id: ObjectId (5198e20220c9b0dc40419385), num: [519, 3]} {_ id: Obj
Apsaradb for MongoDB 2.4 and later versions are more user-friendly for space query.$ GeoWithin, translated from: http://docs.mongodb.org/manual/reference/operator/geoWithin/#op._S_geoWithin
$ Geowithin
Use in mongodb2.4$ GeoWithinThe operator (or function, also the same as below) replaces the discarded$Operator.$ GeoWithinAn operator is another specific point, line, or other geometric element that supports
In many cases, some slow queries cause a lot of pressure on MongoDB. It took some time to write a script and kill some slow query operations.
Var j = 0;
Var _ DEF_TIME = 10;// Set the slow query time
For(Var I in db. currentOP (). inprog ){
Var op ="";
Var opid;
Var memProg = {}
If(Typeof (undefined) = typeof (db. currentOP (). inprog [I])
Many times, some slow queries cause MongoDB pressure, and it took a while to write a script loop to kill some slow query operations
The code is as follows
Copy Code
var j = 0;var _def_time = 10; Set slow query timefor (Var i in Db.currentop (). InProg) {var op = "";var opid;var Memprog = {}if (typeof (undefined) = = typeof (Db.current
Db. Collection name. Find ({condition}). Count ()
can also be associated with a
Db. Collection name. Count ({condition})
Example 1: Statistics on the number of males
Db.stu.find ({gender:1}). Count ()
Example 2: Number of males with a statistical age greater than 20
Db.stu.count ({age:{$gt: 20},gender:1}) 5. Eliminate duplication
Method Distinct () to de-weight the data
Grammar
Db. Collection name. Distinct (' Redo field ', {
the PRINT statement to print out the object information returned by the above statement, further verifying that the return value is as we guessed. Here userid This field is originally a document name in the collection, which is understood as a field name in a table. This is equivalent to the property of an object. *///loop with anything, as long as you can control the number of times, do not because the data volume is too large to cause the operation failed. for (info = Db.info.findOne ({"useri
Query.all ("name", "a", "B");//match array with multiple elementsQuery.and (Query.eq ("name", "a"), Query.eq ("title", "T"));//satisfy multiple conditions at the same timeQuery.eq ("name", "a");//equalsQuery.exists ("type", true);//Determine if key value existsQUERY.GT ("value", 2);//Greater Than >Query.gte ("Value", 3);//greater than or equal to >=Query.in ("name", "a", "B");//Includes all values specified, you can specify different types of conditions and valuesquery.lt ("value", 9);//Less tha
Some enterprises are using non-relational databases such as mongodb in Kunming. Therefore, they must have basic knowledge of non-relational databases in any case, this time I sorted out some of the most basic operations for adding, deleting, modifying, and querying mongodb.
1. Insert data
A simple table structure may be a single column of json. However, if the situation is complicated, nesting may occur.
We know that MongoDB is a non-relational database, so its query method is very different from the standard Structured Query Language SQL. But no matter how complicated it is, when it passes through the developer's hands,
We know that MongoDB is a non-relational database, so its que
MongoDB Federated Query2012-04-15 16:32:44| Category: MongoDB | Tags:mongodb mongodb Federated Query | Report | Font size Big medium small subscription 1. Simple manual correlationFirst, the results are queried and put into a variable, and then queryu = Db.user.findOne ({author: "Wangwenlong"});For (var p =
The problem I'm encountering is someone else
mongodb storing the picture information in
key , for
img ,
value an
url array.
When I use
php an
mongodb extension to query, the
img field returns a string, but what I want to get is the array object that was deposited, what method can I get to an object of an array type?
My
Query records
Common Query
> Var cursor = dB. Things. Find ();
> While (cursor. hasnext () printjson (cursor. Next ());The above example shows the cursor-style iterative output. The hasnext () function tells us whether there is any data. If so, you can call the next () function.
When we use JavaScript shell, we can use the JS features, and foreach can output the cursor. the following example uses foreach (
; var now = Math.floor ((New Date (). GetTime ())/$)//seconds since epoch right no W
> Db.oplog.rs.find ({"TS": {"$lt": Timestamp (now, 1), "$GT": Timestamp (Now-secs_per_hour, 1)}}Query for Oplog within a certain time period (of course, note that UTC is stored)> var since = Math.floor (Isodate ("2014-08-12t09:00:00.000z"). GetTime ()/+)
> var until = Math.floor ( Isodate ("2014-08-12t15:00:00.000z"). GetTime ()/
> Db.oplog.rs.find ({"TS": {"$lt": Tim
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.