跟著教程做了一個(gè)node.js+mongodb的站點(diǎn),其中在Schema中對(duì)集合的定義如下:var?JobSchema?=?new?mongoose.Schema({
????jobtype:String,
????title:String,
????content:String,
????meta:{
????????createAt:{
????????????type:Date,
????????????default:Date.now()
????????},
????????updateAt:{
????????????type:Date,
????????????default:Date.now()
????????}
????}
})在statics中,調(diào)用數(shù)據(jù)庫(kù)的方法如下:JobSchema.statics?=?{
????//fetch用于取出數(shù)據(jù)庫(kù)中所有數(shù)據(jù)
????//findById用于根據(jù)id取出單條數(shù)據(jù)
????fetch:?function(cb){
????????return?this
????????.find({})
????????.sort('meta.updateAt')
????????.exec(cb)
????},
????findById:function(id,?cb){
????????return?this
????????.findOne({_id:id})
????????.exec(cb)
????}
}但如果想根據(jù)updateAt或createAt的時(shí)間段來查詢,不知道應(yīng)該如何寫以下是我試著寫的,但不能查出結(jié)果,也沒有錯(cuò)誤提示信息,只是返回值為空findByDate:function(dates,?cb){
????return?this
????.find({meta:{updateAt:{$gte:dates}}})
????.sort('meta.updateAt')
????.exec(cb)
}
mongoose新手,內(nèi)嵌文檔時(shí)間類型如何查詢
醉生夢(mèng)死012
2017-03-02 14:09:29