mongodb基础学习

来源:互联网 发布:王路 知乎 编辑:程序博客网 时间:2024/05/20 16:12
1.https://cnodejs.org/topic/524040e9101e574521760713
http://www.yiibai.com/mongodb/mongodb_quick_guide.html
    3剑客
http://my.oschina.net/chenhao901007/blog/312367

Create a Jade template files named "index.jade" in the views directory, with the following content.

html  head    title!= title  body    h1!= message

Then create a route to render the "index.jade" file.

app.get('/',function(req, res){  res.render('index',{ title:'Hey', message:'Hello there!'});})

On making a request to the home page, "index.jade" will be rendered as HTML.

服务端返回网页,不如返回值,客户端判断符合条件,然后跳转本地的html
2.不显示_id字段,显示需要的字段
> db.node_book.find({},{"book_name":1,"author":1,_id:0})
3.查找某个条件的数据
> db.node_book.find({"book_name":"123"},{"book_name":1,"author":1,_id:0})
db.node_book.find({"book_name":"123","author" : "mfy1"},{"book_name":1,"author":1,_id:0})
插入数据
db.node_book.insert({"book_name":"123", "author" : "mfy"})
db.node_book.insert({"book_name":"123", "author" : "mfy1"})
db.node_book.insert({"book_name":"1234", "author" : "mfy1"})
在node的查询代码也可以类似用
4.数据库操作的2个文件放在文件夹
数据库的配置文件放在根目录下
0 0