- 分类:【MongoDd】
- 浏览【1097】
- 评论【0】
- 更新【2018-9-06 17:21:31】
使用mongoose建立了连接以后,通过model查询数据,如:testModel.find(),既不报错又不返回数据。 const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/my_database'); 使用mongoose.connect连接产生在mongoose.connection上,使用mongoose.createConnection是反回一个连接对象,建立model的时候需要使用这个连接才有效,此时使用mongoose.model是无效的。 const conn = mongoo
阅读全文- 分类:【Nodejs】
- 浏览【2124】
- 评论【0】
- 更新【2017-8-23 11:20:12】
Unhandled rejection CastError: Cast to ObjectId failed for value "catalog" at path "_id" for model "Blog" at MongooseError.CastError (e:\workspace\yuedun_ts\node_modules\mongoose\lib\error\cast.js:27:11) at ObjectId.cast (e:\workspace\yuedun_ts\node_modules\mong
阅读全文- 分类:【MongoDd】
- 浏览【2056】
- 评论【0】
- 更新【2017-8-18 16:18:36】
`open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client Db.prototype.authenticate method will no longer be available in the next major
阅读全文- 分类:【MongoDd】
- 浏览【3636】
- 评论【0】
- 更新【2017-6-10 12:44:55】
export var CommentSchema: Schema = new Schema({ Id: String, content: String, status: { type: Boolean, default: true } }, { timestamps: true}); 添加{ timestamps: true}选项即可,如果需要自定义属性名称可以直接指定: { timestamps: {createdAt:'created_at', updatedAt:'updated_at'}}
阅读全文- 分类:【MongoDd】
- 浏览【5172】
- 评论【0】
- 更新【2016-11-05 13:51:40】
需求说明:在mongdb中使用模糊查询,就像sql中的like查询,在where条件中使用模糊匹配,当然最重要的是需要模糊查询的字符串是动态传入的 以一篇文章为例,content字段为文章内容,我们要查询文章内容中包含Nodejs关键字的文章 mongodb中查询 select * from articles where content like '%Nodejs%'; db.articles.find( { content: /Nodejs/i } ) Article.find({ content: /Nodejs/i}, function (err, docs) {}); 这种写法
阅读全文- 分类:【MongoDd】
- 浏览【2273】
- 评论【0】
- 更新【2016-11-02 17:32:39】
mongdb查询某一字段sum值 需求说明:articles有一个字段pv记录了该文章的访问量,现在要统计所有文章访问量,类似于sql中的sum统计 mongodb中查询 select sum(pv) from articles; db.articles.aggregate([{$group:{_id:null,pv:{$sum:"$pv"}}}]); 结果:{ "_id" : null, "pv" : 2 } select sum(pv) from articles where createDate <= '2016-1
阅读全文- 分类:【MongoDd】
- 浏览【1773】
- 评论【0】
- 更新【2014-10-17 13:01:08】
随着吐槽的内容越来越多,单页显示就显得不够文雅了,分页功能是一个完整系统必备的。所以就决定加上这个功能,不过分页实现起来并不容易,找了下前辈们的资料,感觉都很复杂,所以还是实现一个简单翻页好了,就是只有上一页,下一页这样简单的功能。 首先看下mongoose API,find方法源码: Model.find = funct
阅读全文