国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

node.js - 使用mongoose的cursor的問題

瀏覽:106日期:2024-07-25 17:58:39

問題描述

自己測試過成功的樣例,自己新建了個集合插入了幾條數(shù)據(jù):

//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); }});

node.js - 使用mongoose的cursor的問題

數(shù)據(jù)是可以都拿到的

但是我去試自己爬蟲爬到的數(shù)據(jù)集合,只取4條數(shù)據(jù)出來,就有問題:

//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); }});

node.js - 使用mongoose的cursor的問題

然后卡這兒就不會動了,代碼都是一致的,怎么就取不出數(shù)據(jù)來呢,求解

問題解答

回答1:

感覺你遇到的情況是cursor是空的。

檢查一下:

1、在mongo下面使用相同的條件查詢一下,看是否有返回的文檔。

相關(guān)文章:
主站蜘蛛池模板: 湄潭县| 博罗县| 东山县| 紫金县| 遂宁市| 新野县| 上林县| 凤冈县| 南阳市| 南靖县| 庆安县| 深水埗区| 沽源县| 易门县| 宜春市| 望江县| 疏勒县| 仁化县| 鹿泉市| 永新县| 南溪县| 肇州县| 仪征市| 剑阁县| 巨野县| 项城市| 寻乌县| 平阴县| 博客| 苗栗市| 两当县| 当阳市| 克什克腾旗| 库尔勒市| 资源县| 施秉县| 武川县| 洱源县| 龙井市| 巧家县| 大丰市|