node.js - 使用mongoose的cursor的問題
問題描述
自己測試過成功的樣例,自己新建了個集合插入了幾條數據:
//testSchema.jsvar mongoose = require(’./db.js’), Schema = mongoose.Schema;var TestSchema = new Schema({ name: {type: String}, age: {type: Number}})var TestModel = mongoose.model(’stream’, TestSchema, ’stream’);var cache = [];var co = require(’co’);co(function*() { 'use strict'; const cursor = TestModel.find({}).cursor(); for (let doc = yield cursor.next(); doc != null; doc = yield cursor.next()) {console.log(doc); }});
數據是可以都拿到的
但是我去試自己爬蟲爬到的數據集合,只取4條數據出來,就有問題:
//test.jsvar mongoose = require(’./db.js’), Schema = mongoose.Schema;var LagouSchema = new Schema({ name: {type: String}, cid: {type: Number}, process: {type: String}, content: {type: String}, url: {type: String}, tag: {type: String}, total: {type: Number}, salary: {type: Array}});var Lagou = mongoose.model(’lagou’, LagouSchema, ’lagou’);var co = require(’co’);co(function*() { 'use strict'; const cursor = Lagou.find({’cid’: {$gte:22777, $lte:22780}}).cursor(); for (let doc = yield cursor.next(); doc != null; doc = yield cursor.next()) {console.log(doc); }});
然后卡這兒就不會動了,代碼都是一致的,怎么就取不出數據來呢,求解
問題解答
回答1:感覺你遇到的情況是cursor是空的。
檢查一下:
1、在mongo下面使用相同的條件查詢一下,看是否有返回的文檔。
相關文章:
1. javascript - 從mysql獲取json數據,前端怎么處理轉換解析json類型2. mysql - AttributeError: ’module’ object has no attribute ’MatchType’3. javascript - 學習網頁開發,關于head區域一段腳本的疑惑4. Whitelabel錯誤頁面發生意外錯誤(類型=未找到,狀態= 404)/WEB-INF/views/home.jsp5. angular.js - ng-grid 和tabset一起用時,grid width默認特別小6. dockerfile - 為什么docker容器啟動不了?7. javascript - JS設置Video視頻對象的currentTime時出現了問題,IE,Edge,火狐,都可以設置,反而chrom卻...8. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應9. macos - mac下docker如何設置代理10. 熱切期待朱老師的回復,網頁視頻在線播放器插件配置錯誤
