1、把A库的test集合 复制到B库
在A库下执行下面的脚本
db.test.find().forEach(
function(d){
db.getSiblingDB('B')['test'].insert(d);
}
);
2、创建索引
对A集合中a字段添加索引
db.A.createIndex({"a":1})
3、查看A集合的索引有哪些
db.A.getIndexes()
4、删除指定的索引
删除集合A中 索引名为a的索引
db.A.dropIndex("a")
5、查看集合A的指定字段a的值aValue
db.getCollection('A').find({"a":"aValue"})
6、修改集合A中字段
a的数据类型 由数值型变为 字符型
b的数据类型 由数值型变为 字符型
db.getCollection('A').find().forEach(function(x) {
x.a = String(x.a);
x.b = String(x.b);
db.getCollection('ext_iphone_no_info').save(x);
})
7、查看集合A中的总条数
db.A.count({})
集合A中的a字段等于aValue的总条数
db.A.count({"a" : "aValue"})