我希望在插入时使用上限集合来查找数据库。但是我的.find
方法中有一些错误并且不知道如何修复它?我应该使用游标来执行此操作吗?
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);
});
});
});