db.users.find({"CardCode":{"$in":['FZ00103','FZ00068']}}) --in
db.users.find({"CardCode":{"$nin":['FZ00103','FZ00068']}}) --not in
db.users.find({},{'CardCode':1,'CardName':1}) - -只返回列CardCode,CardName
db.users.find({'CardCode':'FZ00078'}) --返回CardCode=FZ00078
db.users.find({'CardCode':'FZ00078'},{'CardCode':1,'CardName':1}) --返回CardCode=FZ00078,只返回CardCode,CardName两列
db.getCollection('xxxx').count() – 返回集合中有多少条记录
db.getCollection('xxxx').remove({}) --删除集合,不会删除索引
db.getCollection('xxxx').drop({}) –删除整个集合包含索引,然后重新创建集合和索引
db.getCollection('xxxx').sort({'field':-1}) -- 排序,-1降序,1升序
网友评论