0

my code only works if i remove the limit function, what im doing wrong?

var db = mongojs('yansite', ['yansite']);
(function () {
    var bulk = db.ips.initializeOrderedBulkOp();
    bulk.find({}).limit(2).remove();
    bulk.execute(function (err, res) {
        console.log('Done!')
    });
})();

error is:

TypeError: bulk.find(...).limit is not a function at D:\nodeprojects\mysite\server.js:281:19 at Object. (D:\nodeprojects\mysite\server.js:285:3) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:390:7) at startup (bootstrap_node.js:150:9)

in mongojs github README it shows this example:

db.mycollection.find({}).limit(2).skip(1, function (err, docs) { ... })

1 Answers1

0

i did it but kinda ugly i wish there was a way, its hard to believe there isn't

(function () {
    db.usersChatMessages.find({}).limit(2, function (err, doc) {
        console.log('Done!');
        var docIds = [];
        for (var i=0; i < doc.length; i++) {
            docIds.push(doc[i]._id);
        }
        db.usersChatMessages.remove({_id: {$exists: true, $in: docIds}}, function (err, doc) {
            console.log('removed!');
        });
    });
})();