I am trying to filter a data collection by making a query and storing the results in a smaller collection. However, the number of records that were found using count() and the number in the collection are very different(count() is much higher). Am I doing something wrong?
This returns about 110 million.
db.getCollection('ex').count({
'data.points': {$exists: true},
'data.points.points': {$exists: false},
}, {
'data.id': 1,
'data.author.id': 1
})
Then I execute this.
db.getCollection('ex').find({
'data.points': {$exists: true},
'data.points.points': {$exists: false},
}, {
'data.id': 1,
'data.author.id': 1
})
.forEach(function (doc) {
db.s_uid_wid.insert(doc)
})
But this only gives about 5 million records. They should be exactly the same. What is going on?
db.getCollection('s_uid_wid').count({})
2016-02-04T00:39:21.735+0800 Error: getMore: cursor didn't exist on server, possible restart or timeout? at src/mongo/shell/query.js:116
The following fixes the problem. It takes about one day to complete the insertion.
db.getCollection('ex').find({
'data.points': {$exists: true},
'data.points.points': {$exists: false},
}, {
'data.id': 1,
'data.author.id': 1
}).addOption(DBQuery.Option.noTimeout)
.forEach(function (doc) {
db.s_uid_wid.insert(doc)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With