Home > php教程 > PHP源码 > body text

mongodb学习笔记2(简单增删查改)

PHP中文网
Release: 2016-05-25 17:04:51
Original
1318 people have browsed it

1.增加一条数据。昨天也练习了一下,今天又进一步巩固。主要有两种方法,一种是save,一种是insert。举例:db.blog.save(({"name":"taotao","address":{"city":"beijing","post":"100096"},"phone":"64645646"}))或者db.blog.insert(({"name":"taotao","address":{"city":"beijing","post":"100096"},"phone":"15210340214"}))。另外可以先给一个变量赋值,然后插入这个变量即可。例如
post={
... "name" : "taotao",
... "address" : {
... "city" : "beijing",
... "post" : "100096"
... },
... "phone" : "15210340214"
... }
db.blog.insert(post);
2,删除一条记录db.集合名.remove(条件);如:db.blog.remove({"name":"ysz"})删除集合中name为ysz的数据
删除全部记录 db.集合名.remove();不写任何条件就相当于删除所有数据。如:db.blog.remove();
3.查询所有记录db.集合名.find();如:db.blog.find();查找集合lblog中所有数据
查询所有记录db.集合名.findOne(条件);如:db.blog.findOne({"name":"ysz"});查找集合中name为ysz的数据
这是简单的查询,明天学习各种条件查询。
4.修改记录db.集合名.update(条件);db.blog.update({"name":"ysz"},{"name":"taotao"})按理说不写条件,应该是全部修改的,但实际结果却只修改了一条,这个先存疑。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template