Skip to content
方法说明语法
新增MongoDBdb.getCollection('user').insert({"userId" : "014","uclass" : "B","name" : "Back","age" : 11,"email" : "b14@sina.com","birthday" : ISODate("2018-07-31T03:46:13.885Z"),"dataStatus" : 1});
MySQLINSERT INTO sz-temp.user (userId, uclass, name, age, email, birthday, dataStatus) VALUES ('014', 'B', 'Back13', '20', 'b14@sina.com', '2013-07-31 11:46:13', '0');
方法说明语法
删除MongoDBdb.getCollection('user').remove({"userId":"014"});
MySQLdelete from user where userId = '014';
方法说明语法
修改MongoDBdb.getCollection('user').update({"userId":"013"}, {$set:{"email":"b13@sina.com", "age":20}});
MySQLupdate user set email = 'b13@sina.com', age = 20 where userId = '013';
方法说明语法
查询所有MongoDBdb.getCollection('user').find({});
MySQLselect * from user;
查询条件:=MongoDBdb.getCollection('user').find({"age":16});等效于db.getCollection('user').find({"age":{$eq:16}});
MySQLselect * from user where age = 16;
查询条件:likeMongoDBdb.getCollection('user').find({"name":/Ba/});
MySQLselect * from user where name like '%Ba%';
查询条件:distinctMongoDBdb.getCollection('user').distinct("name");
MySQLselect distinct uclass from user u;
查询条件:>MongoDBdb.getCollection('user').find({"age":{$gt:16}});
MySQLselect * from user where age >16;
查询条件:>=MongoDBdb.getCollection('user').find({"age":{$gte:16}});
MySQLselect * from user where age >= 16;
查询条件:<MongoDBdb.getCollection('user').find({"age":{$lt:16}});
MySQLselect * from user where age < 16;
查询条件:<=MongoDBdb.getCollection('user').find({"age":{$lte:16}});
MySQLselect * from user where age 16;
查询条件:orMongoDBdb.getCollection('user').find({$or:[{"uclass":"A"},{"class":"B"}]});
MySQLselect * from user where uclass = 'A' or uclass = 'B';
查询条件:时间MongoDBdb.getCollection('user').find({"birthday":{$gt: new Date("2008-08-14T06:24:40.110Z"), $lt: new Date("2015-08-14T06:14:40.089Z")}});
MySQLselect * from user where birthday > '2008-08-14 06:24:40' and birthday < '2015-08-14 06:14:40';
查询条件:countMongoDBdb.getCollection('user').find({"uclass":"A"}).count();
MySQLselect count(1) from user where uclass = 'A';
查询条件:sort升序MongoDBdb.getCollection('user').find({}).sort({"age":1});
MySQLselect * from user order by age asc;
查询条件:sort降序MongoDBdb.getCollection('user').find({}).sort({"age":-1});
MySQLselect * from user order by age desc;