collectionA collection is a container in which n multiple data can be placed insideThis data can be filtered, sorteddb.remove a document from the collection parameter 1: Filter criteria. Parameter 2: Optional parameter, whether single row delete, default false. db.Ordb.{upsert:true,multi:true}) update a document in a collectionParameter one: Update the condition of the documentParameter two: Update operators used when updating, and update propertiesCommon operators: $inc recursive the field va
Each mongodb server supports multiple databases. For security and convenience management, each database is independent, and the data of each database is also stored separately.
A database consists of one or more sets, and documents (objects) are stored in the collection. An optional security certificate can control access.
Command
Introduction
The mongo database has a concept of database commands. Database
Tags: exsi conversion switch Call and Zha des count () border After the successful start of MongoDB, and then open a command line window input MONGO, you can do some of the database operations. Enter help to see the basic Operations Command: Show DBS: Display Database list Show Collections: Displays a collection in the current database (similar to a table in a relational database) Show Users: Show user Use MongoD
Label:Learn a little bit every day, progress a little, record a little, share a little, summarize a little. First, the basic application 1. Common commands Show DBS Display Database list Use dbname into the dbname database, case sensitive, no this database does not matter Show Collections displays a collection in the database, equivalent to a table 2. Create and add Db.users.save ({"Name": "LECAF"}) created a collection named users and added a new {"N
Label:MongoDB Common commands: Talk about a special situation, if the admin uses encryption, then you create a database must be encrypted to use, this is the problem I personally met. Enter the MongoDB command line, note: The default entry is the test library $mongo//admin is the core group of database management, the total permissions console, stored the user name password role and other information. Cre
TableName where key01=valu01 and key02=valu02Not equal to Operation: Db.collections.find ({key01:{$ne: valu01}}); SELECT * from TableName where key01 $not Related actions: Db.collections.find ({key:{$not: {$in: [valu01,valu02]}}}); SELECT * from TableName where key not in (VALU01,VALU02)Note: Db.collections.find (key:{$not: valu01}); No such wording.Regular Expressions: Follow-up studiesRelated Operations for arrays$mod: Modulo function$inc$maxscan: Make the maximum number of scanned documents
Tags: mongodbMONGO official website Http://www.mongodb.org/downloadsVue Tools Download http://www.mongovue.com/downloads/Build a folder, put the extracted MONGO file, in the new one put the specified databaseMake a variable, specify binThe following folders and paths can be customizedMongod--dbpath D:\installSoft\mongoDbDATAMONGO 127.0.0.1:27017/adminHere is a simple commandDownload MongoDB specified path datamongod--dbpath e:\
does not replace the original data, so the correct way to update it is as follows:Db.unicorns.update ({name: ' Jingdong '}, {$set: {weight:590}})Db.unicorns.update ({name: ' Pilot '}, {$inc: {If there is an update, add db.hits.update ({page: ' Unicorns '}, {$inc: {hits:1}}, True);d b.hits.find (), or True (upset) using the third parameter setting, default is False#批量更新db. Unicorns.update ({}, {$set: {vaccinated:true}});d B.unicorns.find ({vaccinated:true}); All data will not be vaccinated is up
Db.createcollection ("tablename")//CREATE TABLE
Use Password to access
Use admin
Db.adduser ("admin", "admin")//here must set the password, otherwise the test database settings password is not valid
Db.auth ("admin", "admin")
Use test
Db.adduser ("Test", "test")
============================= Other Commands ================================
Db. AddUser (username,password) Add user
Db.auth (Usrename,password) Set up database connection verif
Label:1. Add the user to the TD database using use TD and then execute Db.adduser ("name", "password"); can be added;2. Enable users to use Db.auth ("name", "password");3. Generally in the project we want to enable security checks, in the configuration of the MongoDB database path at the time after adding--auth so that the security check is started, not the database user is not able to operate the database;4. Delete a user using Db.system.users.remove
Label:The MongoDB shell is more than just an interactive shell, it also supports execution of specified JavaScript files, and also supports execution of specified command fragments. With this feature, MongoDB can be combined with the Linux shell to do most of the daily management and maintenance work.executes the specified commandFor example, there are several common ways to query the number of records in t
}). ForEach (Printjson);Db.users.find ({age: {$lte: +}}, {age:true}). ForEach (Printjson);Exclude The Age columnDb.users.find ({age: {$lte: +}}, {Age:false}). ForEach (Printjson); 9. The Foreach transfer function displays informationDb.things.find ({x:4}). ForEach (function (x) {print (Tojson (x));}); Some of the commands that you might use: $ne: Not equal to$GT: Greater Than$LT: Less than$gte: greater than or equal to$lte: Less than or equal to Curr
to the database you want to create:
1
> use testdb;
To create a user:
1234567
db.createUser({user: "testUser",pwd: "testPass",roles: [ { role: "readWrite", db: "testdb"}] })
Sign in with your new account:
1
> db.auth("testUser","testPass")
Creates a new collection in the current database;
1
> db.table1.save({"id":"1"})
Displays the collection of the current database:
Show DBS View all databasesShow Tables View all collectionsdb Displays the current databaseuse+name switches to the specified database and creates a new if it does not existA document is a set of key-value (Key-value) pairs (that is, Bson). MongoDB documents do not need to set the same fields, and the same fields do not require the same data type{"Name": 2, "Age": 169}{"Name": "Óin", "Age": 167}{"Bianhao": +, "age": 82}Create a fixed-size collection d
})---------------------------------------------------------------------------------The number of cursor jump queries and qualified returnsDb.department.find (). Skip (10)Select top Ten *from department;Db.department.find (). Limit (10)---------------------------------------------------------------------------------The value returns the specified field, the first map writes the filter condition, the second map writes the returned field, and the default returns _ID, if it is not necessary to set t
: "3100000"}, {hostid: "3200000"}, "TAG1") Due to the current primary bit shard0003,Sh.addtagrange ("Mydb.location", {hostid: "3200000"}, {hostid: "3300000"}, "TAG2")Sh.addtagrange ("Mydb.location", {hostid: "3300000"}, {hostid: "3500000"}, "TAG3")Sh.addtagrange ("Mydb.location", {hostid: "3500000"}, {$maxKey: 1}, "TAG3") 4. Add ChunckPut the primary on the second shardDb.runcommand ({moveprimary: "MyDB", To: "shard0001"})View Shard ConditionDb.chunks.find ({ns: "Mydb.location"}) Manually establ
Take the maximum value of the Time field: Db.getcollection (' Calllog '). Find (). Sort ({"Time": -1}). Limit (1) Minimum value only need to change –1 to 1 Db.getcollection (' Calllog '). Find (). Sort ({"Time": 1}). Limit (1) Appcode field is not equal to "100001" record Db.getcollection (' Calllog '). Find ({"Appcode": {$ne: "100001"}}) Support Db.colls.find ({"field": {$gt: Value}});Db.colls.find ({"field": {$lt: Value}});Db.colls.find ({"field": {$gte: Value}});Db.colls.find ({"field": {$l
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.