1. Export mongodb data, Tomas access information data, User-function Usage, right-click, Export Collection, can be saved as json or csv format.
2. In mongodb database, only the index contained in the primary key is duplicate data. An index is the same, not duplicate data. The primary key is the unique index of the collection.
1)mongodb data aggregation
db.faultDetailInfo.aggregate([{$match: {"state":{$in:["Fixed", "Dismissed", "New"]}}},{$group: {_id:{"entry name":"$entry name", "state":"$state"}, "Number":{$sum:1}}},])
pipe of coverity person statistics:
db.faultDetailInfo.aggregate([{$match:{"Overlap code":{$gte:79,$lte:86}}},{$group:{_id:{"owner":"$owner"},"Number":{$sum:1}}},])
db.eNbLocationInfo.aggregate([{$match:{"Date of introduction" : "2017-05-08"}},{$group:{_id:"$Local market",total:{$sum:1}}}])Aggregate function
2)mongodb data query
db.repairColl.find({"plate name": {regex:/68/,nin: [/8968/]})
mongodb looks at the data of a field
db.repairAnalysisInfo.find({"serial number" : "219101631054"})
Fuzzy query
db.AlarmCfgInfo.find({"classification":{$regex:/BBU.*/}})
nested queries
db.customer.find({"login_user.phone":"110"})
mongodb to see what dates are available in May
db.repairAnalysisInfo.distinct("RMA Audit date",{"RMA Audit date":/2017-05/})
Find records for "A" or "D" in status
db.test.find({status:{$in:["A","D"]}})
Find a record with status as "A" and age greater than 30
db.test.find( { status: "A", age: { $lt: 30 } } )
The query matches only those documents that contain a name field with a value of null (excluding records where name does not exist), that is, the value of the entry field is Null in the BSON type (that is, 10)
db.test.find({name:{$type:10}})
In order to make the search case-insensitive, mongodb uses options with a value parameter i. The following command searches for the string: yiibai.com, case or case:
db.posts.find({post_text:{$regex:"yiibai",$options:"$i"}})
There is no MEID record in the network element of the query home device
db.test.find({"Network Element of Home Equipment":{$regex: "^((?!MEID).)*$"}})
3) Delete records with serial numbers beginning with ** (e.g. 21)
db.repairColl.remove({"serial number":/^21/})
4) Query the unique values in the collection and update them.
allDate, _ := RestoreDatedbobject.GetDistinct("_id.Alarm recovery date", bson.M{"_id.Local market": cityName})
cityDate.UpdateOne(bson.M{"Local market": cityName}, bson.M{"$addToSet": bson.M{"Alarm date": bson.M{"$each": allDate}}})
5) Add or delete a nested field
Add nested fields
db.globalStatCache.update({"_id" : ObjectId("58b54dda2677e343786b8f98")},{$set:{"Playback content.06ac070bb4c20c922cf5a6eedc295244":""}},{multi:true})
//Delete nested fields
db.globalStatCache.update({"_id" : ObjectId("58b54dda2677e343786b8f98")},{$unset:{"Playback content.06ac070bb4c20c922cf5a6eedc295244":""}},{multi:true})
6) Delete a field
Db. AlarmCfgInfo. update ({"_id": ObjectId ("5817f964c9d3aba570a84a1e")}, {$unset:{"BBU veneer type list":'}, false, false) delete fields, the last false, the first matching search Delete "host-[VVE136AUS-1.60]-" from the list of veneer types
db.AssetCfgInfo.update({"_id" : ObjectId("595c92feb1862a1450061754")},{"$pull":{"Single Board Type List":"host-[VVE136AUS-1.60]-"}})
7) Delete records
db.test.remove({"_id" : ObjectId("5940fdebda54ee1e9ce84d27")})
8) Change the field name
Db. Asset CfgInfo. update ({"_id": ObjectId ("5940 fdebda54ee1e9ce84d27")}, {$rename:{"A": "B"}, false, true) Change the field name (from "A" to "B")
9) Change the value of the field
Db. Asset CfgInfo. update ({"_id": ObjectId ("5940 fdebda54ee1e9ce84d27")}, {set:{"classification":"A"}) Change the value of the field ("A" is the changed value)
10) Add one or more values to a field
Add a value to a field
db.AssetCfgInfo.update({"_id" : ObjectId("595c92feb1862a1450061754")},{$push:{"Single Board Type List":"THUB"}})
Adding multiple values to a field
b.AssetCfgInfo.update({"_id" : ObjectId("595c92feb1862a1450061754")},{$pushAll:{"Single Board Type List":["THUB","UBPG1"]}})
11) Add an index to the collection, run in the background, uniquely index, and rename it
db.unicom_detailInfo.ensureIndex({"Date of office repairs" : -1,"serial number" :1},{"background":true,"unique":true,"name":"RepairInfo_repairCollNew_uniqueIndex"})
1. The inc modifier inc can add or subtract keys with a value of a document that is numeric (only the number that meets the requirements).
db.b.find()
{ "_id" : ObjectId("5003b6135af21ff428dafbe6"), "uid" : "201203", "type" : "1",
"size" : 13 }
db.b.update({"uid" : "201203"},{"$inc":{"size" : -1}})
db.b.find()
{ "_id" : ObjectId("5003b6135af21ff428dafbe6"), "uid" : "201203", "type" : "1",
"size" : 12 }
2.set is used to specify a key and update the key value if the key does not exist and is created. For embedded documents, when using set updates, use "." connection.
db.c.update({"name":"toyota"},{"$set":{"size.width":7}})
db.c.findOne({"name":"toyota"})
{
"_id" : ObjectId("5003be465af21ff428dafbe7"),
"name" : "toyota",
"type" : "suv",
"size" : {
"height" : 8,
"width" : 7,
"length" : 15
}
}
3. When unset uses the modifier unset, it can delete the target key whether it uses 1, 0, -1 or a specific string for the target key.
4. $push - Adds an array element to a key of an array type in a document, but filters duplicate data. Adding a key exists, requiring that the key value type must be an array; if the key does not exist, the key of the array type is created.
db.AssetCfgInfo.update({"_id" : ObjectId("595c92feb1862a1450061754")},{$pushAll:{"Single Board Type List":["THUB","UBPG1","UBPI","UBPM","UCI","UES0"]}})
5. $pop deletes elements from the beginning or end of an array. Delete from the tail of the array
db.c.update({"name" : "toyota"},{$pop:{"title":1}})
From the head of the array - 1 or 0
db.c.update({"name" : "toyota"},{$pop:{"title":-1}})
6, $pull deletes qualified elements from the array
db.c.update({"name" : "toyota"},{$pull:{"title":"t2"}})
7. "lt","lte", "gt","gte" corresponds to <,<=,>,>, respectively.=