在MongoDB中,將創(chuàng)建數(shù)據(jù)庫(kù)和表當(dāng)?shù)谝淮尾迦霐?shù)據(jù)時(shí)自動(dòng)。
在MongoDB中,將創(chuàng)建數(shù)據(jù)庫(kù)和表當(dāng)?shù)谝淮尾迦霐?shù)據(jù)時(shí)自動(dòng)。...
在以下示例中,插入新記錄后,數(shù)據(jù)庫(kù)“java2s"和表“用戶(hù)"是即時(shí)創(chuàng)建的。
$ ./mongo > use java2s switched to db java2s ? > db.users.insert({username:"java2s",password:"123456"}) > db.users.find() { "_id" : ObjectId("the id value"), "username" : "java2s", "password" : "123456" }
在以下示例中,插入新記錄后,數(shù)據(jù)庫(kù)“java2s"和表“用戶(hù)"是即時(shí)創(chuàng)建的。...
要插入記錄,請(qǐng)使用db.yourTableName.insert({data})或db.tablename.save({data})。
> db.users.save({username:"abc",password:"abc123"}) > db.users.find()
要插入記錄,請(qǐng)使用db.yourTableName.insert({data})或db.tablename.save({data})。...
> db.users.update({username:"java2s"},{$set:{password:"hello123"}}) > db.users.find()
要查找或查詢(xún)記錄,請(qǐng)使用db.tablename.find({criteria})。
列出所有記錄:
> db.users.find()
查找用戶(hù)名為“google"的記錄
> db.users.find({username:"abc"})
查找用戶(hù)名長(zhǎng)度小于或等于2的記錄。
db.users.find({$where:"this.username.length<=2"})
查找存在用戶(hù)名字段的記錄。
db.users.find({username:{$exists : true}})
要?jiǎng)h除記錄,請(qǐng)使用db.tablename.remove({criteria})。
> db.users.remove({username:"google"}) > db.users.find()
列出表“用戶(hù)"的所有索引,默認(rèn)情況下列“_id"是始終是主鍵并自動(dòng)創(chuàng)建。
> db.users.getIndexes() >
列出表“用戶(hù)"的所有索引,默認(rèn)情況下列“_id"是始終是主鍵并自動(dòng)創(chuàng)建。...
> db.users.ensureIndex({username:1}) > db.users.getIndexes()
要?jiǎng)h除索引,請(qǐng)使用db.table_name.drop Index(column)。在以下示例中,列“username"的索引被刪除。
> db.users.dropIndex({username:1}) > db.users.getIndexes() >
要?jiǎng)h除索引,請(qǐng)使用db.table_name.drop Index(column)。在以下示例中,列“username"的索引被刪除。...
> db.users.ensureIndex({username:1},{unique:true}); > db.users.getIndexes()
列出所有可用的命令。
> help db.help() help on db methods db.mycoll.help() help on collection methods ...
列出所有可用的命令。...
> db.help() DB methods: db.addUser(username, password[, readOnly=false]) db.auth(username, password) ...
db.collection.help() - 顯示關(guān)于集合(表)的幫助。
> db.users.help() DBCollection help db.users.find().help() - show DBCursor help db.users.count() db.users.dataSize() ...
db.collection.help() - 顯示關(guān)于集合(表)的幫助。...
> db.users.find().help() find() modifiers .sort( {...} ) .limit( n ) .skip( n ) .count() .size() .explain([verbose]) ...
更多建議: