-- 增
db.stu.insert({
"name":"zhangsan",
"age":24,
})
db.stu.insert({
"_id":"99",
"name":"xiaoming",
"age":27,
"area":"shanghai"
})
db.stu.insert(
[
{"_id":"12",
"name":"wangwu",
"age":32},
{"name":"qianqian",
"age":25}
]
)
-- 删
db.stu.remove({}) 删 全部
db.stu.remove(
{"name":"qianqian"}
)
db.stu.remove(
{"age":15},true
)
-- 改
-- $set 修改某个值
-- $unset 删除某个列
-- $rename 重命名某个列
-- $inc 增长某个列
db.stu.update(
{"name":"wangwu"},{$set:{"age":19}}
);
-- 查
db.stu.find();
db.stu.find(
{"name":"xiaoming"}
)
db.stu.find(
{"name":"xiaoming"},{"age":1}
)
db.stu.findOne()
$ne 不等于
db.stu.find(
{"age":{$ne:24}}
)
--$in @ $nin
db.stu.find(
{"age":{$nin:[14,19]}}
)
--$exists
--and
db.stu.find(
{"age":24 ,"name":"zhangsan"}
)
$where 不推荐
db.stu.find(
{$where:"this.age ==19 &&this.name=='zhangsan'"}
)