1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| > db.auth("admin","admin")
> db.createUser({ user:'user',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
> show dbs
> use hello > db.hello.insert({"hello":"world"}) > show dbs
> use hello > db.dropDatabase()
> db.createCollection(name, options)
> db.createCollection("test") > db.createCollection("mycol", { capped : true, autoIndexId : true, size : 6142800, max : 10000 } ) > show collections
> db.collection.drop()
> db.hello1.drop()
> db.COLLECTION_NAME.insert(document)
> db.col.insert({title: '测试', description: '测试', tags: ['mongodb', 'database', 'NoSQL'], likes: 100 }) > db.col.find()
> db.collection.update( <query>, <update>, { upsert: <boolean>, multi: <boolean>, writeConcern: <document> } )
> db.col.update({'title':'测试'},{$set:{'title':'MongoDB'}})
> db.collection.remove( <query>, { justOne: <boolean>, writeConcern: <document> } ) > db.col.remove({'title':'测试'}) > db.COLLECTION_NAME.remove(DELETION_CRITERIA,1)
|