Reputation: 3
I want to use capped colletion to find database when the insertion happens.but i have some errors in my .find
method and don't know how to fix it?should i use cursor to do this?
url = require("url"),
emitter = require("events").EventEmitter,
assert = require("assert"),
mongo = require("mongodb"),
Cursor = mongo.Cursor;
var uristring = "mongodb://localhost:27017/test";
var mongoUrl = url.parse (uristring);
mongo.MongoClient.connect (uristring, function (err, db) {
db.collection ("test", function (err,collection) {
collection.isCapped(function (err, capped) {
if (!capped) {
console.log (collection.collectionName + " is not a capped collection");
}
collection.find({},{name:1,_id:0}).sort({$natural: -1}).toArray.stream()(function(err, results) {
console.log(results);
});
});
});
Upvotes: 0
Views: 66
Reputation: 2064
Rather than doing a find(), I think what you want to do is use a tailable cursor.
Upvotes: 1