function (from, collection, query) {
assert( isString(from) && from.length );
assert( isString(collection) && collection.length );
collection = this._name + "." + collection;
query = query || {};
return this._dbCommand( { cloneCollection:collection, from:from, query:query
} );
}
from string 包含需要复制的表的mongodb实例主机名 collection string 数据实例中需要复制的表名,该命令只可以复制远程mongodb实例上相同数据库名称的表 query document 可选的选项。标准的查询语句过滤掉不需要的文档
{ "_id" : ObjectId("53687d9df433cf04b788c6d1"), "name" : "dog" }
{ "_id" : ObjectId("53687ff1f433cf04b788c6d2"), "name" : "cat" }
{ "_id" : ObjectId("53687ff4f433cf04b788c6d3"), "name" : "tiger" }
db.cloneCollection("192.168.11.52", "bar", {"name" : "tiger"})
db.bar.find();
{ "_id" : ObjectId("53687ff4f433cf04b788c6d3"), "name" : "tiger" }
hostname string 包含需要复制的数据库的mongodb实例主机名
function (from) {
assert( isString(from) && from.length );
return this._dbCommand( { clone: from } );
}
use mydb
db.dropDatabase();
db.cloneDatabase("192.168.11.52");
db.copyDatabase是copydb数据库命令的一个外在体现。
function (fromdb, todb, fromhost, username, password) {
assert( isString(fromdb) && fromdb.length );
assert( isString(todb) && todb.length );
fromhost = fromhost || "";
if ( username && password ) {
var n = this._adminCommand( { copydbgetnonce : 1, fromhost:fromhost } );
return this._adminCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb,
todb:todb, username:username, nonce:n.nonce, key:this.__pwHash( n.nonce, userna
me, password ) } );
} else {
return this._adminCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb,
todb:todb } );
}
}
fromdb string 源数据库名称 todb string 目标数据库名称 fromhost string 可选项,源数据库的主机名。如果是同一主机,忽略该选项 username string 可选项,源主机名用户名 password string 可选项,源主机名用户名对应密码
{ resource: { db: "mySourceDB", collection: "system.indexes" }, actions: [ "find" ] }
{ resource: { db: "mySourceDB", collection: "system.namespaces" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.js" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.users" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.roles" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.version" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.indexes" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.namespaces" }, actions: [ "find" ] }
{ resource: { db: "myTargetDB", collection: "" }, actions: [ "insert", "createIndex" ] }
{ resource: { db: "myTargetDB", collection: "system.js" }, actions: [ "insert" ] }
resource: { db: "myTargetDB", collection: "" }, actions: [ "insert", "createIndex" ] },
{ resource: { db: "myTargetDB", collection: "system.js" }, actions: [ "insert" ] },
{ resource: { db: "myTargetDB", collection: "system.users" }, actions: [ "insert" ] },
{ resource: { db: "myTargetDB", collection: "system.roles" }, actions: [ "insert" ] },
{ resource: { db: "myTargetDB", collection: "system.version" }, actions: [ "insert" ] }
db.copyDatabase("mydb", "newmydb", "192.168.11.52");
{ cloneCollection: "<namespace>", from: "<hostname>", query: { <query> } }
cloneCollection string 集合的命名空间,命名空间包含了数据库名和集合名的组合 from string 指定远程主机名和可选的端口号 query document 可选的,过滤选项
{ "_id" : ObjectId("53687d9df433cf04b788c6d1"), "name" : "dog" }
{ "_id" : ObjectId("53687ff1f433cf04b788c6d2"), "name" : "cat" }
{ "_id" : ObjectId("53687ff4f433cf04b788c6d3"), "name" : "tiger" }
db.runCommand({cloneCollection : "mydb.bar", from : "192.168.11.52:27017", query : {"name" : "tiger"}})
use mydb
db.bar.find()
{ "_id" : ObjectId("53687ff4f433cf04b788c6d3"), "name" : "tiger" }
db.runCommand({cloneCollectionAsCapped : "bar", toCollection : "barone", size : 100})
db.barone.isCapped();
true
{ clone: "db1.example.net:27017" }
{ copydb: 1,
fromhost: <hostname>,
fromdb: <database>,
todb: <database>,
slaveOk: <bool>,
username: <username>,
nonce: <nonce>,
key: <key> }
fromhost string 运行mongodb实例的远程源主机,如果是本地可以忽略 fromdb string 源数据库名称 todb string 目标数据库名称 slaveOk boolean 可选的,设置为true,允许从从库复制库 username string 可选的,远程主机的用户名。 nonce string 可选的,远程主机的共享密钥 key string 可选的,远程主机的认证密码哈希
{ resource: { db: "mySourceDB", collection: "" }, actions: [ "find" ] }
{ resource: { db: "mySourceDB", collection: "system.js" }, actions: [ "find" ] }
{ resource: { db: "mySourceDB", collection: "system.indexes" }, actions: [ "find" ] }
{ resource: { db: "mySourceDB", collection: "system.namespaces" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.js" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.users" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.roles" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.version" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.indexes" }, actions: [ "find" ] }
{ resource: { db: "admin", collection: "system.namespaces" }, actions: [ "find" ] }
{ resource: { db: "myTargetDB", collection: "" }, actions: [ "insert", "createIndex" ] }
{ resource: { db: "myTargetDB", collection: "system.js" }, actions: [ "insert" ] }
resource: { db: "myTargetDB", collection: "" }, actions: [ "insert", "createIndex" ] },
{ resource: { db: "myTargetDB", collection: "system.js" }, actions: [ "insert" ] },
{ resource: { db: "myTargetDB", collection: "system.users" }, actions: [ "insert" ] },
{ resource: { db: "myTargetDB", collection: "system.roles" }, actions: [ "insert" ] },
{ resource: { db: "myTargetDB", collection: "system.version" }, actions: [ "insert" ] }
use admin
mynonce = db.runCommand( { copydbgetnonce : 1, fromhost: <hostname> } ).nonce
hex_md5(mynonce + username + hex_md5(username + ":mongo:" + password))
db._adminCommand({
copydb : 1,
fromdb : "mydb",
todb : "mydbtwo",
formhost : "192.168.11.52"
})
{ "ok" : 1 }
use admin
mynonce = db.runCommand( { copydbgetnonce : 1, fromhost: "192.168.11.51:27017" } ).nonce
mykey = hex_md5(mynonce + "test" + hex_md5("test" + ":mongo:" + "caoqing"))
db._adminCommand({
copydb: 1,
fromdb: "mydb",
todb: "mydbthree",
fromhost: "192.168.11.51",
username: "test",
nonce: mynonce,
key: mykey
})
{ "ok" : 1 }
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有