软件下载吧文章资讯

分类分类

mongodb 命令行下及php中insert数据详解

2024-03-26 14:43作者:下载吧

前面说了到数据库连接操作,请参考:mongodb 添加用户及权限设置详解
对数据库的操作:请参考:mongodb 数据库操作详解–创建,切换,删除
下面说一下,数据库表的插入操作
1,命令行下的insert操作

> use test;    #切换到test数据库 
switched to db test 
 
> document=({"title" : "linux命令", "auther" : "tank" });   #定义了一个变量 
{ "title" : "linux命令", "auther" : "tank" } 
> db.test.insert(document);     #插入变量 
> db.test.find();       #查看插入的数据 
{ "_id" : ObjectId("53c8fc1cf062ac30ee8b9d2d"), "title" : "linux命令", "auther" : "tank" } 
 
> db.test.insert({"title" : "51yip", "auther" : "tank" });  #直接插入数据 
> db.test.find();       #查看 
{ "_id" : ObjectId("53c8fc1cf062ac30ee8b9d2d"), "title" : "linux命令", "auther" : "tank" } 
{ "_id" : ObjectId("53c8f6fff062ac30ee8b9d2e"), "title" : "51yip", "auther" : "tank" } 
展开全部

相关文章

说两句网友评论
    我要跟贴
    取消